-
Notifications
You must be signed in to change notification settings - Fork 47
fix(javascript-sdk): use-prompt-none #329
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ const allowedErrors = { | |
| NetworkError: 'NetworkError when attempting to fetch resource.', | ||
| // Webkit browser error | ||
| CORSError: 'Cross-origin redirection', | ||
|
|
||
| // prompt=none errors | ||
| InteractionNotAllowed: 'The request requires some interaction that is not allowed.', | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -46,14 +49,14 @@ const allowedErrors = { | |
| abstract class OAuth2Client { | ||
| public static async createAuthorizeUrl(options: GetAuthorizationUrlOptions): Promise<string> { | ||
| const { clientId, middleware, redirectUri, scope } = Config.get(options); | ||
|
|
||
| const requestParams: StringDict<string | undefined> = { | ||
| ...options.query, | ||
| client_id: clientId, | ||
| redirect_uri: redirectUri, | ||
| response_type: options.responseType, | ||
| scope, | ||
| state: options.state, | ||
| ...(options.prompt ? { prompt: options.prompt } : {}), | ||
| }; | ||
|
|
||
| if (options.verifier) { | ||
|
|
@@ -82,7 +85,8 @@ abstract class OAuth2Client { | |
| * New Name: getAuthCodeByIframe | ||
| */ | ||
| public static async getAuthCodeByIframe(options: GetAuthorizationUrlOptions): Promise<string> { | ||
| const url = await this.createAuthorizeUrl(options); | ||
| const url = await this.createAuthorizeUrl({ ...options, prompt: 'none' }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that we are setting prompt=none as a default, does it make sense to make this something the developer can specify? As I understand it, setting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question. This is how I look at it: since this is within the hidden iframe, I don't believe there is ever a reason to NOT use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Given this and my point about the value |
||
|
|
||
| const { serverConfig } = Config.get(options); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ interface GetAuthorizationUrlOptions extends ConfigOptions { | |
| state?: string; | ||
| verifier?: string; | ||
| query?: StringDict<string>; | ||
| prompt?: 'none' | 'login' | 'consent'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that the requirement in the ticket was for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point. These three values for the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is misleading if it doesn't actually do anything or isn't compatible in the context of the SDK and should be removed. I'd worry that it might inadvertently trick developers into thinking some action should occur if they specify consent, for example showing a consent collection page. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,9 +118,12 @@ abstract class TokenManager { | |
| */ | ||
| const verifier = PKCE.createVerifier(); | ||
| const state = PKCE.createState(); | ||
| const authorizeUrlOptions = { ...options, responseType: ResponseType.Code, state, verifier }; | ||
| const authorizeUrl = await OAuth2Client.createAuthorizeUrl(authorizeUrlOptions); | ||
|
|
||
| const authorizeUrlOptions = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this got formatted /shrug |
||
| ...options, | ||
| responseType: ResponseType.Code, | ||
| state, | ||
| verifier, | ||
| }; | ||
| /** | ||
| * Attempt to call the authorize URL to retrieve authorization code | ||
| */ | ||
|
|
@@ -155,6 +158,7 @@ abstract class TokenManager { | |
| allowedErrors.AuthorizationTimeout !== err.message && | ||
| allowedErrors.FailedToFetch !== err.message && | ||
| allowedErrors.NetworkError !== err.message && | ||
| allowedErrors.InteractionNotAllowed !== err.message && | ||
| // Safari has a very long error message, so we check for a substring | ||
| !err.message.includes(allowedErrors.CORSError) | ||
| ) { | ||
|
|
@@ -165,6 +169,9 @@ abstract class TokenManager { | |
|
|
||
| // Since `login` is configured for "redirect", store authorize values and redirect | ||
| window.sessionStorage.setItem(clientId as string, JSON.stringify(authorizeUrlOptions)); | ||
|
|
||
| const authorizeUrl = await OAuth2Client.createAuthorizeUrl(authorizeUrlOptions); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i moved this from above, not needed but its closer to where its used now |
||
|
|
||
| return window.location.assign(authorizeUrl); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused here. Being that the
parseErrormethod concatenates theerroranderror_description, I would think this string would start withinteraction_required:: https://github.com/ForgeRock/forgerock-javascript-sdk/blob/develop/packages/javascript-sdk/src/oauth2-client/index.ts#L296. Am I misunderstanding what happens here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay, you're right. Sorry for the confusion.