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

Add support for code flow silent-refresh and popup #609

Merged

Conversation

KevinCathcart
Copy link

@KevinCathcart KevinCathcart commented Aug 19, 2019

This adds support for "prompt=none" style silent-refresh for the code flow, and popup support too since it was only a a tiny bit more work. This fixes #600 and fixes #602.

The most significant change here was altering the silent refresh process to be fully based on events rather than the legacy callbacks. After receiving an original event or the timeout signal, it will emit the correct silent_refresh event, just like the existing code did. These changes should be entirely backwards compatible, since the same events will be emitted.

LoginOptions has been added to the code flow, since being able to pass specific values to it is required for either silent refresh or popup to work for code flow. I've only added support for the
non-deprecated properties, and not added support for disableOAuth2StateCheck since I'm not sure when that is actually useful. (The nonce is always added to the state, and only a terribly non-conformant OIDC server would fail to return the state parameter. )

The names of some of the properties are a bit misleading, since they say "Hash", but can apply to query-strings in code flow. I've not renamed them, since that would be a breaking change. I have, however, updated the JSDoc comments.

@jeroenheijmans
Copy link
Collaborator

Fantastic! This looks like a great PR to me, I have no comments based on looking at the code.

Would be good if someone can find a moment to do a functional test with these changes, for both implicit and pkce flows. I'll try to find some time, but no promises, unfortunately.

@KevinCathcart
Copy link
Author

These changes are working for me for a PKCE based code flow, but it would certainly be good to have somebody else verify that these work for them. I have absolutely not tested implicit mode with these, so while I'm relatively confident they still work, I'm not certain about that.

It would be nice to be able to hide the deprecated options properties from intellisense, so that people are not trying to use them with code flow, and getting burned by that. Unfortunately I've found no clean way of doing that which would not break existing tryLogin calls intended for the implicit flow, which would almost certainly break a large fraction of existing users. More specifically, I could do it rather easily for tryLoginCodeFlow, but that does not really help when using regular tryLogin.

@cgatian
Copy link
Contributor

cgatian commented Sep 5, 2019

@manfredsteyer do you have of when this can be merged? Per @jeroenheijmans are we waiting on unit tests?

@commeyner
Copy link

@manfredsteyer when do you think this will be merged? We really need this PR. Thanks!

projects/lib/src/types.ts Outdated Show resolved Hide resolved
@cgatian
Copy link
Contributor

cgatian commented Sep 25, 2019

@manfredsteyer @jeroenheijmans Sorry to keep pinging about this. This is definitely a needed feature by our team.

@dozer75
Copy link

dozer75 commented Oct 9, 2019

It's quiet about this :( Would really have this merged soon since it's critical in the move from implicit to code with pkce.

* pass the iframes hash fragment to this method.
* pass the iframes hash fragment to this method, and
* is also used by popup flows in the same manner.
* This can be used with code flow, where is must be set

Choose a reason for hiding this comment

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

Typo: is instead of it

@daltonwallace
Copy link

Any update on this? We would love to use this library but really need this feature.

@andifalk
Copy link

Any update on this? We would love to use this library but really need this feature.

In the meantime, you can also use this library (auth code+PKCE + refresh tokens) if your authorization server follows the recommended attack mitigations for refresh tokens mentioned in https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-04#section-8 and https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13#section-4.12

@daltonwallace
Copy link

daltonwallace commented Nov 23, 2019

@andifalk thanks for your suggestion! We're using Okta and unfortunately their UI doesn't even allow you to enable refreh_tokens if you're trying to authorize with a SPA

@andifalk
Copy link

@andifalk thanks for your suggestion! We're using Okta and unfortunately their UI doesn't even allow you to enable refreh_tokens if you're trying to authorize with a SPA

@daltonwallace you could try to configure a native client instead of SPA in okta. This gives the option of authcode+PKCE and refresh tokens as well.

@daltonwallace
Copy link

@andifalk also a good suggestion. I actually tried that and Okta gave me an error saying the request can't come from a browser 🤦‍♂️

@andifalk
Copy link

@andifalk also a good suggestion. I actually tried that and Okta gave me an error saying the request can't come from a browser 🤦‍♂️

@daltonwallace oh that is bad. Just read that okta does Not want to support refresh tokens for spa instead of offering settings to limit the lifetime of refresh tokens

@fdipuma
Copy link

fdipuma commented Nov 29, 2019

I'm also very interested in this PR. Is there any reason why this isn't merged yet?

@aschaible
Copy link

Please merge this!! 💯

@FolabiAhn
Copy link

I hope this will be merged soon. Really need this

@lbuyse
Copy link

lbuyse commented Feb 3, 2020

Please merge this , we really need this as well to integrate authorisation code+PKCE with our wso2 identity server which is also not supporting refresh token grant for SPA

@@ -195,7 +195,7 @@ export class OAuthService extends AuthConfig implements OnDestroy {
}

protected refreshInternal(params, noPrompt) {
if (this.responseType === 'code') {
if (!this.silentRefreshRedirectUri && this.responseType === 'code') {

Choose a reason for hiding this comment

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

@KevinCathcart wouldn't it also be possible to check if there is a refreshToken available, instead of checking if the silentRefreshRedirectUri ist configured?

@manfredsteyer manfredsteyer merged commit 4e1bca9 into manfredsteyer:master Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet