amazon-cognito-identity-jsã«å¼·ãä¾å.
signIn()å ã§createCognitoUserãã¦ããcreateCognitoUserã¯CognitoUser()ã®ã©ããã¼ã
public signIn(username: string, password: string): Promise<any> { ... const user = this.createCognitoUser(username); const authDetails = new AuthenticationDetails({ Username: username, Password: password }); const that = this; return new Promise((resolve, reject) => { user.authenticateUser(authDetails, {
createCognitoUserã¡ã½ããã®å
ã¯ã©ã¹ (AuthClass) ãuserPoolå±æ§ãæã£ã¦ãã¦ããã®ä¸ã«clientãªãã¸ã§ã¯ãããã¾ã£ã¦ããã
Auth.configureã§CognitoUserPool (amazon-cognito-identity-jsç±æ¥) ã使ã£ã¦usePoolãè¨å®ãã¦ãã®ã§ãããããããã§ä¸æã«æ±ºã¾ã£ã¦ããã
Auth.configure(config)ã®configã«å
¥ã£ã¦ãããã®ãã¾ãã¾ä½¿ããã¦ããããã®ä¸ã«endpointããã模æ§ãAmplifyãã§ãã¯ï¼
private createCognitoUser(username: string): Cognito.CognitoUser { const userData: ICognitoUserData = { Username: username, Pool: this.userPool, }; ... return new CognitoUser(userData); }
CognitoUserã³ã³ã¹ãã©ã¯ã¿ã§dataãå¼æ°ã«ã¨ããããã§this.client (Clientã¯ã©ã¹) ã«data.Pool.clientãè¨å®ã
export default class CognitoUser { constructor(data) { ... this.username = data.Username || ''; this.pool = data.Pool; this.Session = null; this.client = data.Pool.client;
Clientã®ã³ã³ã¹ãã©ã¯ã¿ã§endpointãåãåã£ã¦ã以éã¯ä¸åããããªããnullã®å ´åã¯cognito-idp...ã®ãã¡ã¤ã³ã«ãªãã
client.requestã®ãªã¯ã¨ã¹ãå
ãã¡ã¤ã³ã¯ããã§æ±ºã¾ãã
// Facet.ts import * as Cognito from 'amazon-cognito-identity-js';
// /src/Common/index.ts export * from './Facet';
// /src/Auth/Auth.ts import { AWS, Cognito, ..., } from '../Common';
ãªã¯ã¨ã¹ãå®ä½
// @param {CognitoUserPool} data.Pool
this.client = data.Pool.client;
import Client from './Client';
CognitoUserPoolã³ã³ã¹ãã©ã¯ã¿å
this.client = new Client(region, endpoint);
client.requestã¯ã·ã³ãã«ãªfetch()
aws-amplify/Client.js at master · aws/aws-amplify · GitHub
ãã¹ã¯ã¼ãã§ã®ãã¤ã¬ã¯ãèªè¨¼ã¯ã¡ã¤ã³ã¨ãéããªã
authenticateUserDefaultAuthãè²ã
ãã£ã¦ã¦é¢ç½ã
InitiateAuthãªã¯ã¨ã¹ãããã¦ã
RespondToAuthChallengeãªã¯ã¨ã¹ããã¦ã
ããã¥ã¡ã³ãã«ãããããã
ææ°ã®èªè¨¼ããã¼ã¯ã¦ã¼ã¶ã¼ã®ã¢ã¤ãã³ãã£ãã£ãæ¤è¨¼ããããããã¹ã¯ã¼ãã®ä»ã«æ°ãããã£ã¬ã³ã¸ã¿ã¤ããçµã¿è¾¼ãã§ãã¾ããå½ç¤¾ã§ã¯ 2 ã¤ã®ä¸è¬çãªã¹ãããã§èªè¨¼ãå®ååããInitiateAuth 㨠RespondToAuthChallenge ã¨ãã 2 ã¤ã® API ã使ç¨ãã¦å®è£ ãã¾ãã
Secure Remote Password (SRP) ãããã³ã«
ãã¹ã¯ã¼ãããçæããä½ãã§èªè¨¼ãããããã³ã«
ãã¹ã¯ã¼ããéä¿¡è·¯ã«æµããªãã®ã§ã»ãã¥ã¢
SRP è¨ç®ãåé¿ããå ´åã«ã»ãã¥ã¢ãªããã¯ã¨ã³ããµã¼ãã¼ã§ä½¿ç¨ã§ããããã«è¨è¨ããã管ç API ã®ä»£æ¿ã»ãããããã¾ãã
SRPããã¬ãã¯ã¾ãã«èªè¨¼ãªã®ã§ãOIDCãã¹ã³ã¼ãå¤ã«ãã¦ãèªè¨¼é¨åãªãã ãã
ã¤ã¾ãUserPools-IdPã®èªè¨¼é¨åã
ã§ããããã¯ã©ã¤ã¢ã³ãã®ä»äºâ¦ï¼
ããããã£ãã
çµã¿è¾¼ã¿UIã£ã¦ãã®é¨åãæ
å½ã ã
ã¤ã¾ããã³ãã®ãã³ãã®èªè¨¼é¨åã«ãå½ç¶ãèªè¨¼ã¯ã©ã¤ã¢ã³ããå¿
è¦ãªã®ã§ããã®è©±ã
2FAãçµã¿è¾¼ãã ãè²ã
æãå¾ããããä¸è¬åãããå
容ã«ãªã£ã¦ãã¨ããã¼ã
UserPool-IdPã§UserPoolsèªè¨¼ããå ´åãOIDC AuthNãªã¯ã¨ã¹ãã¯èµ°ãã®ããªï¼
resã«ã¯ã©ã¤ã¢ã³ãããã¹ã¯ã¼ãã¶ã¡è¾¼ãã§ããèªè¨¼çãª
- ãã¼ã¹: https://(mydomain).auth.(region).amazoncognito.com
- èªå¯ã¨ã³ããã¤ã³ã: /oauth2/authorize
- ãã¼ã¯ã³ã¨ã³ããã¤ã³ã : /oauth2/token
- ãã°ã¤ã³ã¨ã³ããã¤ã³ã : /login
- ãã°ã¢ã¦ãã¨ã³ããã¤ã³ã : /logout