Sitelet https://github.com/stormpath/express-stormpath/pull/608
Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Refactor authentication to use Okta authorization server - #608

Merged
robertjd merged 9 commits into
4.0.0from
okta-authentication
Mar 17, 2017
Merged

robertjd merged 9 commits into
4.0.0from
okta-authentication

Conversation

@robertjd

@robertjd robertjd commented Mar 9, 2017 •

Copy link
Copy Markdown
Member

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:

  • Example configuration block in changelog should not use literal values, use example values e.g. https://dev-<my org id>.oktapreview.com
  • Remove ES6 code, we've decided not to force a Node upgrade during the transition.
  • The authorization server configuration can be discovered through the API, so we should do this so that the developer only needs to specify their API token and app ID.
  • More help around creating an application and authorization server. I want to create a screencast where I walk through this, as it's a lot of moving parts.
  • New authentication result from Okta oauth endpoint needs to match OAuthPasswordGrantAuthenticationResult as much as posssible
  • Normalize base URL trailing slash
  • Attempt to get some of the IT tests running

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.
@mraible

mraible commented Mar 9, 2017

Copy link
Copy Markdown

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?

@robertjd

robertjd commented Mar 9, 2017

Copy link
Copy Markdown
Member Author

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.

Comment thread docs/changelog.rst Outdated

- **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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp: your

Comment thread docs/changelog.rst Outdated
.. code-block:: javascript
app.use(stormpath.init(app, {
okta: {
org: 'https://dev-613050.oktapreview.com/',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Looks like below we're expecting this to not have the / at the end

return next();
}

if (account.status !== 'ENABLED') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/okta/access-token-authenticator.js Outdated
}

withClientId(clientId) {
this.clientId = clientId;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to also be a fluid function (i.e. return this)?

Comment thread lib/okta/access-token-authenticator.js Outdated
});
}

jwksResolver(kid, callback) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am curious - does njwt cache the keys?

Comment thread lib/okta/access-token-authenticator.js Outdated
return callback('Keys collection not found');
}

const matches = res.keys.filter((key) => key.kid === kid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I like find here instead of filter (will return immediately when it gets the match)

Comment thread lib/okta/get-app-user-by-id.js Outdated

function getAppUserById(org, appId, apiToken, uid, callback) {
const req = {
url: org + '/api/v1/apps/' + appId + '/users/' + uid,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`

Comment thread lib/okta/password-grant.js Outdated

function passwordGrant(config, userFormSubmission, callback) {
var req = {
url: config.okta.org + 'oauth2/' + config.okta.authorizationServerId + '/v1/token',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's normalize it, I'll add to this PR.

Comment thread okta-todo.md
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, nm about the caching question

}

callback(null, expandedAccount, authResult);
callback(null, user, oauthAccessTokenResult);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?

@robertjd robertjd Mar 13, 2017 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@coveralls

coveralls commented Mar 14, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-53.6%) to 13.643% when pulling 3e8953c on okta-authentication into ecd114b on 4.0.0.

- 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
@robertjd
robertjd merged commit aed13fa into 4.0.0 Mar 17, 2017
@robertjd
robertjd deleted the okta-authentication branch March 17, 2017 00:34
@robertjd
robertjd restored the okta-authentication branch March 17, 2017 00:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants