3 回答

TA貢獻1848條經驗 獲得超10個贊
讓我們以 Facebook 為例。當您使用 Cognito UI 時,Facebook 會為您的用戶將 OAuth 令牌直接交給 Cognito。Cognito 會做一些事情,比如檢查用戶是否已經存在,并在需要時創建一個新用戶,然后向您的應用程序發送一個 AWS OAuth 令牌。
現在,如果您想要在自己的網站上使用 Facebook 按鈕,則身份驗證會以不同的方式進行。您必須自己與 Facebook 協商,為用戶取回 OAuth 令牌,然后將訪問令牌交給 Cognito。Cognito 會做它的事情并給你一個 AWS OAuth 令牌。

TA貢獻1943條經驗 獲得超7個贊
您的應用程序要求已經超過了使用千篇一律的 Cognito 登錄流程的程度。
FB.login(function (response) {
? // Check if the user logged in successfully.
? if (response.authResponse) {
? ? console.log('You are now logged in.');
? ? // Add the Facebook access token to the Cognito credentials login map.
? ? AWS.config.credentials = new AWS.CognitoIdentityCredentials({
? ? ? IdentityPoolId: 'IDENTITY_POOL_ID',
? ? ? Logins: {
? ? ? ? 'graph.facebook.com': response.authResponse.accessToken
? ? ? }
? ? });
? ? // Obtain AWS credentials
? ? AWS.config.credentials.get(function(){
? ? ? ? // Access AWS resources here.
? ? });
? } else {
? ? console.log('There was a problem logging you in.');
? }
});
然后像這樣獲取用戶:
? ? var data = { UserPoolId : 'us-east-1_Iqc12345',
? ? ? ? ClientId : '12345du353sm7khjj1q'
? ? };
? ? var userPool = new AmazonCognitoIdentity.CognitoUserPool(data);
? ? var cognitoUser = userPool.getCurrentUser();
? ? if (cognitoUser != null) {
? ? ? ? cognitoUser.getSession(function(err, session) {
? ? ? ? ? ? if (err) {
? ? ? ? ? ? ? ? alert(err);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? console.log('session validity: ' + session.isValid());
? ? ? ? });
? ? }
在這里您可以看到一個名為 AdminInitiateAuth 的函數。還有將用戶附加到身份提供者的功能。因此,雖然使用 JS SDK 可能是最簡單的,但在我看來,這是將 Web 應用程序與 Cognito 集成的解決方案。您可以清楚地處理所有身份驗證流程、令牌管理、創建 api 以登錄、注銷等。服務器端使用 GO SDK

TA貢獻1854條經驗 獲得超8個贊
現在可以使用identity_providerprop in oauth2/authorizerequest
在我的代碼中看起來像
const query = stringify({
response_type: 'code',
redirect_uri: tokenRedirectUri,
state: stateEncoded,
client_id: clientId,
identity_provider: platform,
})
return `https://auth.${domainName}/oauth2/authorize?${query}`
//其他 OIDC 提供商等platform在哪里GoogleFacebook
那只是url,你需要自己制作按鈕,但它會直接重定向到提供者同意
- 3 回答
- 0 關注
- 199 瀏覽
添加回答
舉報