{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/2096","repository_url":"https://api.github.com/repos/strongloop/loopback","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/2096/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/2096/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/2096/events","html_url":"https://github.com/strongloop/loopback/issues/2096","id":135617913,"number":2096,"title":"BUG: Application class resets API keys before every save.","user":{"login":"anagrath","id":2846372,"avatar_url":"https://avatars.githubusercontent.com/u/2846372?v=3","gravatar_id":"","url":"https://api.github.com/users/anagrath","html_url":"https://github.com/anagrath","followers_url":"https://api.github.com/users/anagrath/followers","following_url":"https://api.github.com/users/anagrath/following{/other_user}","gists_url":"https://api.github.com/users/anagrath/gists{/gist_id}","starred_url":"https://api.github.com/users/anagrath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anagrath/subscriptions","organizations_url":"https://api.github.com/users/anagrath/orgs","repos_url":"https://api.github.com/users/anagrath/repos","events_url":"https://api.github.com/users/anagrath/events{/privacy}","received_events_url":"https://api.github.com/users/anagrath/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-02-23T03:17:35Z","updated_at":"2016-09-27T20:48:33Z","closed_at":null,"body":"Here is code from git hub.  Before we go changing all the keys, shouldn't it check if the ctx.isNewInstance?  Difficult to inherit Application otherwise.\r\n```\r\n  /*!\r\n   * A hook to generate keys before creation\r\n   * @param next\r\n   */\r\n  Application.observe('before save', function(ctx, next) {\r\n    if (!ctx.instance) {\r\n      // Partial update - don't generate new keys\r\n      // NOTE(bajtos) This also means that an atomic updateOrCreate\r\n      // will not generate keys when a new record is creatd\r\n      return next();\r\n    }\r\n\r\n    var app = ctx.instance;\r\n    app.created = app.modified = new Date();\r\n    if (!app.id) {\r\n      app.id = generateKey('id', 'md5');\r\n    }\r\n    app.clientKey = generateKey('client');\r\n    app.javaScriptKey = generateKey('javaScript');\r\n    app.restApiKey = generateKey('restApi');\r\n    app.windowsKey = generateKey('windows');\r\n    app.masterKey = generateKey('master');\r\n    next();\r\n  });\r\n```"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/249993870","html_url":"https://github.com/strongloop/loopback/issues/2096#issuecomment-249993870","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/2096","id":249993870,"user":{"login":"anagrath","id":2846372,"avatar_url":"https://avatars.githubusercontent.com/u/2846372?v=3","gravatar_id":"","url":"https://api.github.com/users/anagrath","html_url":"https://github.com/anagrath","followers_url":"https://api.github.com/users/anagrath/followers","following_url":"https://api.github.com/users/anagrath/following{/other_user}","gists_url":"https://api.github.com/users/anagrath/gists{/gist_id}","starred_url":"https://api.github.com/users/anagrath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anagrath/subscriptions","organizations_url":"https://api.github.com/users/anagrath/orgs","repos_url":"https://api.github.com/users/anagrath/repos","events_url":"https://api.github.com/users/anagrath/events{/privacy}","received_events_url":"https://api.github.com/users/anagrath/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T20:48:33Z","updated_at":"2016-09-27T20:48:33Z","body":"Yes, sorry.  Now that I am looking at it again, I was also confused and I can see what happened.\r\n\r\nThe code I pasted was from Application within Loopback.  Every time you save Application, it generates new keys for oAuth.  Which means, if the user just changes the name of the application, too bad, all your old keys are invalid.  The work around I implemented to avoid this checks if there is a new instance.  So the question I was asking is, in the loopback code for the Application, shouldn't we only set new keys if it is a new application and then also only when we call for new keys via API?\r\n\r\nThe work around I implemented does that, but it seems loopback should behave that way since it is unexpected behavior for the Application to automatically take new keys.  I remember this was a difficult issue to debug because the oAuth keys for the devices I was configuring would be set, and then all of a sudden would no longer work for no explanation."}}
{"actor":{"display_login":"anagrath"}}