Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Handling of ClientID for Password Grant #1679

Merged
merged 12 commits into from
Mar 21, 2019

Conversation

ekristen
Copy link
Contributor

@ekristen ekristen commented Sep 21, 2018

  • Fixes how client_id is passed on Password Grant for OAuth2.
  • Adds support for client_secret and passing it as well for Password Grant if set.

References on Password Grants:

Fixes #1678

@ekristen
Copy link
Contributor Author

Fixes #1678

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

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

I think you're right actually about client_id belonging in a query param actually and this was wrong all along 🙀. This is a breaking change though and we'd have to add a flag for opting in to the new behavior together with a deprecation if we find that flag to be false.

Regarding client_secret: there is no way that I'm aware of for effectively using that in a client side JS app where you'd necessarily have to publish your client_secret and thus make it useless.

@default null
@public
*/
clientSecret: null,
Copy link
Member

Choose a reason for hiding this comment

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

This was intentionally left out - as soon as you publish your client secret as part of your publicly accessible Ember app it's no longer a secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I got a little over zealous, I'll remove it.

@ekristen
Copy link
Contributor Author

@marcoow if you can provide guidance on how to feature flag something (I'm pretty new to the ember world) I'll gladly fix this.

@marcoow
Copy link
Member

marcoow commented Sep 24, 2018

Sure, don't worry - happy to help. So what we'll have to do is:

  • add a property sendClientIdAsQueryParam to addon/authenticators/oauth2-password-grant.js and default that to false
  • enable the new behavior that you add in this MR only when sendClientIdAsQueryParam is true
  • show a deprecation when sendClientIdAsQueryParam is false (from init in addon/authenticators/oauth2-password-grant.js)
  • when we release the next major version, we can remove the flag, the deprecation and the old behavior

The idea behind this is that people who update to the next major version get the deprecation and can opt-in to the new behavior and validate that it works with their OAuth 2.0 server. Once the next major version is released, they just remove the flag. At the same time, we don't have to release this as a breaking change (yet) though.

@ekristen
Copy link
Contributor Author

@marcoow I'm not sure how to add deprecation notices but the rest should be in properly now.

@marcoow
Copy link
Member

marcoow commented Sep 24, 2018

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

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

This looks good to me but it's missing some tests actually 😬


if (data['grant_type'] === 'password' && this.get('refreshAccessTokens')) {
data['offline_token'] = true;
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can open a second pull request if you like. It's actually required if you want access tokens to be refreshed by an Oauth2 server that's been implemented to spec. Generally you have to pass the offline_token as well as have the server allow for tokens to be refreshed.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I can't find any reference to "offline_token" in https://tools.ietf.org/html/rfc6749… Anyway, I'd put this in a separate PR for simplicity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have to dig a bit more, but it looks it might not be a spec thing, but instead an opinionated option that many oauth2 services implement. The most common being offline_token in the body, but Auth0 implements it as a scope.

I think it's important to look at adding because many require it.

@ekristen
Copy link
Contributor Author

I'll look at how to add tests for this.

@marcoow
Copy link
Member

marcoow commented Sep 24, 2018 via email

@marcoow
Copy link
Member

marcoow commented Oct 22, 2018

@ekristen: any update on the tests? Would be great to get this in.

@ekristen
Copy link
Contributor Author

Test to check for client_id in the body when sendClientIdAsQueryParam is set to true is now in place. Unfortunately GitHub is broken at the moment, all webhooks and background processing is not working, so we will have to wait for Travis later on.

@ekristen
Copy link
Contributor Author

@marcoow forgot to mention you previously ^

@ekristen
Copy link
Contributor Author

@marcoow following up

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

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

Sorry for the late reply 🙏 I left some comments around the deprecation - we should make sure it only shows when the deprecated behavior is used.

@@ -31,6 +32,18 @@ const keys = Object.keys || emberKeys; // Ember.keys deprecated in 1.13
@public
*/
export default BaseAuthenticator.extend({
init() {
this._super(...arguments);
deprecate(`Ember Simple Auth: Client ID as Authorization Header is deprecated in favour of Client ID as Query String Parameter.`,
Copy link
Member

Choose a reason for hiding this comment

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

This should not actually be in the init as using the authenticator as such is totally fine - just leaving sendClientIdAsQueryParam as false is deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved the authenticate, triggers only if set to false.

addon/authenticators/oauth2-password-grant.js Outdated Show resolved Hide resolved
addon/authenticators/oauth2-password-grant.js Outdated Show resolved Hide resolved
tests/unit/authenticators/oauth2-password-grant-test.js Outdated Show resolved Hide resolved
@ekristen
Copy link
Contributor Author

ekristen commented Dec 7, 2018

Hopefully it's ok now? Tests pass for me locally.

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

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

left one more comment 😬

Also rebase on the latest master - that should fix CI

tests/unit/authenticators/oauth2-password-grant-test.js Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants