-
Notifications
You must be signed in to change notification settings - Fork 4k
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(cognito): user pool identity provider with support for Facebook & Amazon #8134
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
287aa8b
Identity Provider basics
b3533a3
overhaul - rev2
4f4f26e
SupportedIdentityProviders on Client
33b765d
Add README entry
05a9e53
drop apple
00ce0d5
split & rename
5fde776
Merge branch 'master' into nija-at/cognito-userpool-idp
ericzbeard 24c675d
Merge branch 'master' into cognito-userpool-idp
05b06f0
fix up integ test
ee21d0e
PR feedback
f2bba19
More feedback
a2a036e
Merge branch 'master' into nija-at/cognito-userpool-idp
mergify[bot] 6d78104
Merge branch 'master' into nija-at/cognito-userpool-idp
a910700
Merge branch 'master' into nija-at/cognito-userpool-idp
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Construct, IResource, Resource } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Represents a UserPoolIdentityProvider | ||
*/ | ||
export interface IUserPoolIdentityProvider extends IResource { | ||
/** | ||
* The primary identifier of this identity provider | ||
* @attribute | ||
*/ | ||
readonly providerName: string; | ||
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 could be typed 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. |
||
} | ||
|
||
/** | ||
* User pool third-party identity providers | ||
*/ | ||
export class UserPoolIdentityProvider { | ||
|
||
/** | ||
* Import an existing UserPoolIdentityProvider | ||
*/ | ||
public static fromProviderName(scope: Construct, id: string, providerName: string): IUserPoolIdentityProvider { | ||
class Import extends Resource implements IUserPoolIdentityProvider { | ||
public readonly providerName: string = providerName; | ||
} | ||
|
||
return new Import(scope, id); | ||
} | ||
|
||
private constructor() {} | ||
} |
52 changes: 52 additions & 0 deletions
52
packages/@aws-cdk/aws-cognito/lib/user-pool-idps/amazon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Construct } from '@aws-cdk/core'; | ||
import { CfnUserPoolIdentityProvider } from '../cognito.generated'; | ||
import { UserPoolIdentityProviderBase, UserPoolIdentityProviderProps } from './base'; | ||
|
||
/** | ||
* Properties to initialize UserPoolAmazonIdentityProvider | ||
*/ | ||
export interface UserPoolIdentityProviderAmazonProps extends UserPoolIdentityProviderProps { | ||
/** | ||
* The client id recognized by 'Login with Amazon' APIs. | ||
* @see https://developer.amazon.com/docs/login-with-amazon/security-profile.html#client-identifier | ||
*/ | ||
readonly clientId: string; | ||
/** | ||
* The client secret to be accompanied with clientId for 'Login with Amazon' APIs to authenticate the client. | ||
* @see https://developer.amazon.com/docs/login-with-amazon/security-profile.html#client-identifier | ||
*/ | ||
readonly clientSecret: string; | ||
/** | ||
* The types of user profile data to obtain for the Amazon profile. | ||
* @see https://developer.amazon.com/docs/login-with-amazon/customer-profile.html | ||
* @default [ profile ] | ||
*/ | ||
readonly scopes?: string[]; | ||
} | ||
|
||
/** | ||
* Represents a identity provider that integrates with 'Login with Amazon' | ||
* @resource AWS::Cognito::UserPoolIdentityProvider | ||
*/ | ||
export class UserPoolIdentityProviderAmazon extends UserPoolIdentityProviderBase { | ||
public readonly providerName: string; | ||
|
||
constructor(scope: Construct, id: string, props: UserPoolIdentityProviderAmazonProps) { | ||
super(scope, id, props); | ||
|
||
const scopes = props.scopes ?? [ 'profile' ]; | ||
|
||
const resource = new CfnUserPoolIdentityProvider(this, 'Resource', { | ||
userPoolId: props.userPool.userPoolId, | ||
providerName: 'LoginWithAmazon', // must be 'LoginWithAmazon' when the type is 'LoginWithAmazon' | ||
providerType: 'LoginWithAmazon', | ||
providerDetails: { | ||
client_id: props.clientId, | ||
client_secret: props.clientSecret, | ||
authorize_scopes: scopes.join(' '), | ||
}, | ||
}); | ||
|
||
this.providerName = super.getResourceNameAttribute(resource.ref); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Construct, Resource } from '@aws-cdk/core'; | ||
import { IUserPool } from '../user-pool'; | ||
import { IUserPoolIdentityProvider } from '../user-pool-idp'; | ||
|
||
/** | ||
* Properties to create a new instance of UserPoolIdentityProvider | ||
*/ | ||
export interface UserPoolIdentityProviderProps { | ||
/** | ||
* The user pool to which this construct provides identities. | ||
*/ | ||
readonly userPool: IUserPool; | ||
} | ||
|
||
/** | ||
* Options to integrate with the various social identity providers. | ||
*/ | ||
export abstract class UserPoolIdentityProviderBase extends Resource implements IUserPoolIdentityProvider { | ||
public abstract readonly providerName: string; | ||
|
||
public constructor(scope: Construct, id: string, props: UserPoolIdentityProviderProps) { | ||
super(scope, id); | ||
props.userPool.registerIdentityProvider(this); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/@aws-cdk/aws-cognito/lib/user-pool-idps/facebook.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Construct } from '@aws-cdk/core'; | ||
import { CfnUserPoolIdentityProvider } from '../cognito.generated'; | ||
import { UserPoolIdentityProviderBase, UserPoolIdentityProviderProps } from './base'; | ||
|
||
/** | ||
* Properties to initialize UserPoolFacebookIdentityProvider | ||
*/ | ||
export interface UserPoolIdentityProviderFacebookProps extends UserPoolIdentityProviderProps { | ||
/** | ||
* The client id recognized by Facebook APIs. | ||
*/ | ||
readonly clientId: string; | ||
/** | ||
* The client secret to be accompanied with clientUd for Facebook to authenticate the client. | ||
* @see https://developers.facebook.com/docs/facebook-login/security#appsecret | ||
*/ | ||
readonly clientSecret: string; | ||
/** | ||
* The list of facebook permissions to obtain for getting access to the Facebook profile. | ||
* @see https://developers.facebook.com/docs/facebook-login/permissions | ||
* @default [ public_profile ] | ||
*/ | ||
readonly scopes?: string[]; | ||
/** | ||
* The Facebook API version to use | ||
* @default - to the oldest version supported by Facebook | ||
*/ | ||
readonly apiVersion?: string; | ||
} | ||
|
||
/** | ||
* Represents a identity provider that integrates with 'Facebook Login' | ||
* @resource AWS::Cognito::UserPoolIdentityProvider | ||
*/ | ||
export class UserPoolIdentityProviderFacebook extends UserPoolIdentityProviderBase { | ||
public readonly providerName: string; | ||
|
||
constructor(scope: Construct, id: string, props: UserPoolIdentityProviderFacebookProps) { | ||
super(scope, id, props); | ||
|
||
const scopes = props.scopes ?? [ 'public_profile' ]; | ||
|
||
const resource = new CfnUserPoolIdentityProvider(this, 'Resource', { | ||
userPoolId: props.userPool.userPoolId, | ||
providerName: 'Facebook', // must be 'Facebook' when the type is 'Facebook' | ||
providerType: 'Facebook', | ||
providerDetails: { | ||
client_id: props.clientId, | ||
client_secret: props.clientSecret, | ||
authorize_scopes: scopes.join(','), | ||
api_version: props.apiVersion, | ||
}, | ||
}); | ||
|
||
this.providerName = super.getResourceNameAttribute(resource.ref); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './base'; | ||
export * from './amazon'; | ||
export * from './facebook'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Holy shit those names :(
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.
Unfortunately namespacing. I don't want it conflicting with https://docs.aws.amazon.com/cognito/latest/developerguide/external-identity-providers.html