-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat(:unlock:): add support for an OAuth flow that triggers social me… #240
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ interface IDeferred<T> { | |
reject: (v: any) => void; | ||
} | ||
|
||
export type IAuthenticationProvider = "arcgis" | "facebook" | "google"; | ||
|
||
/** | ||
* Represents a [credential]((https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-Credential.html)) object used to access a secure ArcGIS resource. | ||
*/ | ||
|
@@ -70,6 +72,11 @@ export interface IOauth2Options { | |
*/ | ||
portal?: string; | ||
|
||
/** | ||
* The authentication provider to use. Defaults to ArcGIS, but Google and Facebook social media logins can also be used. | ||
*/ | ||
provider?: IAuthenticationProvider; | ||
|
||
/** | ||
* Duration (in minutes) that a token will be valid. Defaults to 20160 (two weeks). | ||
*/ | ||
|
@@ -156,6 +163,11 @@ export interface IUserSessionOptions { | |
*/ | ||
portal?: string; | ||
|
||
/** | ||
* The authentication provider to use. Defaults to ArcGIS, but Google and Facebook social media logins can also be used. | ||
*/ | ||
provider?: IAuthenticationProvider; | ||
|
||
/** | ||
* Duration of requested token validity in minutes. Used when requesting tokens with `username` and `password` or when validating the identity of unknown servers. Defaults to two weeks. | ||
*/ | ||
|
@@ -201,6 +213,11 @@ export class UserSession implements IAuthenticationManager { | |
*/ | ||
readonly portal: string; | ||
|
||
/** | ||
* The authentication provider to use. | ||
*/ | ||
readonly provider: IAuthenticationProvider; | ||
|
||
/** | ||
* Determines how long new tokens requested are valid. | ||
*/ | ||
|
@@ -282,9 +299,11 @@ export class UserSession implements IAuthenticationManager { | |
this._token = options.token; | ||
this._tokenExpires = options.tokenExpires; | ||
this.portal = options.portal || "https://www.arcgis.com/sharing/rest"; | ||
this.provider = options.provider || "arcgis"; | ||
this.tokenDuration = options.tokenDuration || 20160; | ||
this.redirectUri = options.redirectUri; | ||
this.refreshTokenTTL = options.refreshTokenTTL || 1440; | ||
|
||
this.trustedServers = {}; | ||
this._pendingTokenRequests = {}; | ||
} | ||
|
@@ -300,6 +319,7 @@ export class UserSession implements IAuthenticationManager { | |
static beginOAuth2(options: IOauth2Options, win: any = window) { | ||
const { | ||
portal, | ||
provider, | ||
clientId, | ||
duration, | ||
redirectUri, | ||
|
@@ -309,17 +329,24 @@ export class UserSession implements IAuthenticationManager { | |
}: IOauth2Options = { | ||
...{ | ||
portal: "https://www.arcgis.com/sharing/rest", | ||
provider: "arcgis", | ||
duration: 20160, | ||
popup: true, | ||
state: options.clientId, | ||
locale: "" | ||
}, | ||
...options | ||
}; | ||
|
||
const url = `${portal}/oauth2/authorize?client_id=${clientId}&response_type=token&expiration=${duration}&redirect_uri=${encodeURIComponent( | ||
redirectUri | ||
)}&state=${state}&locale=${locale}`; | ||
let url: string; | ||
if (provider === "arcgis") { | ||
url = `${portal}/oauth2/authorize?client_id=${clientId}&response_type=token&expiration=${duration}&redirect_uri=${encodeURIComponent( | ||
redirectUri | ||
)}&state=${state}&locale=${locale}`; | ||
} else { | ||
url = `${portal}/oauth2/social/authorize?client_id=${clientId}&socialLoginProviderName=${provider}&autoAccountCreateForSocial=true&response_type=token&expiration=${duration}&redirect_uri=${encodeURIComponent( | ||
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 works for Hub, so you can ignore #239 (comment) - we can add an option for this later if others don't want this behavior. 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. now I'm leaning back the other way: #239 (comment) 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 comments #239 (comment) |
||
redirectUri | ||
)}&state=${state}&locale=${locale}`; | ||
} | ||
|
||
if (!popup) { | ||
win.location.href = url; | ||
|
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.
we may want to say something here like: "Specifying a non-ArcGIS provider will take the user directly to that provider's OAuth page."