Repository navigation
Refactor authentication to use Okta authorization server - #608
Conversation
Authentication now happens against an Okta Authentication Server Token validation is done with the Okta access token, and the application users API. Logout uses revoke on the Authorization Server. Begin writing the changelog for this next major version.
|
What do I need to change in this file to make this work with Okta? https://github.com/stormpath/stormpath-angular2-express-example/blob/master/server/server.js Related: how do I setup my Okta instance to work with this? |
|
Thanks @mraible , great questions. Take a look at the mods to the changelog? If it's not clear let me know and I'll get more detailed. As we go through this migration I want to use the changelog to collect all the notes. |
|
|
||
| - **API Token**: similar to the Stormpath API Key, this is a secret that is used | ||
| to secure the communication with the Okta platorm. | ||
| - **Application Id**: This is the Okta Application that is connected to yuor |
| .. code-block:: javascript | ||
| app.use(stormpath.init(app, { | ||
| okta: { | ||
| org: 'https://dev-613050.oktapreview.com/', |
There was a problem hiding this comment.
nit: Looks like below we're expecting this to not have the / at the end
| return next(); | ||
| } | ||
|
|
||
| if (account.status !== 'ENABLED') { |
There was a problem hiding this comment.
Double checking - in Okta, if a user is not active, it'll return an error right (i.e. so we don't need to keep a check like this)?
There was a problem hiding this comment.
Right. This is a strange check, I'm not sure why it was here in the first place. In this context the authentication attempt has already happened, which would have failed if the user were not enabled.
| } | ||
|
|
||
| withClientId(clientId) { | ||
| this.clientId = clientId; |
There was a problem hiding this comment.
Is this supposed to also be a fluid function (i.e. return this)?
| }); | ||
| } | ||
|
|
||
| jwksResolver(kid, callback) { |
There was a problem hiding this comment.
Am curious - does njwt cache the keys?
| return callback('Keys collection not found'); | ||
| } | ||
|
|
||
| const matches = res.keys.filter((key) => key.kid === kid); |
There was a problem hiding this comment.
nit: I like find here instead of filter (will return immediately when it gets the match)
|
|
||
| function getAppUserById(org, appId, apiToken, uid, callback) { | ||
| const req = { | ||
| url: org + '/api/v1/apps/' + appId + '/users/' + uid, |
There was a problem hiding this comment.
Heh, as an aside, when moving to es6 it's really handy to use template literals for things like this, i.e.
url: `${org}/api/v1/apps/${appId}/users/${uid}`|
|
||
| function passwordGrant(config, userFormSubmission, callback) { | ||
| var req = { | ||
| url: config.okta.org + 'oauth2/' + config.okta.authorizationServerId + '/v1/token', |
There was a problem hiding this comment.
Although if we change the example to not show a trailing '/', then this would need to change. I'm okay with either way, but think we should be consistent (or when processing the config, normalize it).
There was a problem hiding this comment.
Let's normalize it, I'll add to this PR.
| Todo tasks (discovered while implemented Primary goals): | ||
|
|
||
| [ ] ensure that the migrated AS configuration will have the right settings for access token timeouts | ||
| [ ] caching of jwks (can use HTTP response from .well-known) |
There was a problem hiding this comment.
Ah, I see, nm about the caching question
| } | ||
|
|
||
| callback(null, expandedAccount, authResult); | ||
| callback(null, user, oauthAccessTokenResult); |
There was a problem hiding this comment.
Just double checking - are all the objects returned to the user of the same format? I.e. in this case is oauthAccessTokenResult the same as authResult in shape (is this even publicly exposed)?
There was a problem hiding this comment.
Ah, good catch, thanks! I do need to make this match the OAuthPasswordGrantAuthenticationResult as much as possible.
This is now relying on the `okta` branch in the node SDK and stormpath-config I have decided to attempt using this libraries w/ mods, as they already contain these features that will be helpful to not re-write: - configuration parsing - caching - request executor - some getter methods which will still be useful
- No longer fetching the app user, using the user resource itself - Login tests should now be passing - Tests are now expecting some static Okta fixture data, passed through the environment. This may change as we bring more tests back online
Authentication now happens against an Okta Authentication Server
Token validation is done with the Okta access token, and the application users API.
Logout uses revoke on the Authorization Server.
Begin writing the changelog for this next major version.
Tests will be failing in this PR, as I have not yet addressed the functional differences, or the change to ES6 classes.
This branch still requires you to provide Stormpath configuration somewhere, as I haven't yet removed those dependencies.
Todos:
https://dev-<my org id>.oktapreview.comOAuthPasswordGrantAuthenticationResultas much as posssible