2016-11-26 88 views
1

我需要使用JavaScript SDK實現開發人員身份驗證身份,但我面臨着問題。我已經配置了身份池使用自定義身份驗證提供AWS Cognito開發人員使用JavaScript SDK驗證身份

在服務器:

AWS.config = new AWS.Config({ 
    region: 'ap-northeast-2', 
    credentials: new AWS.Credentials('XXXXXS7FJBAOO5IXXXXX', 'XXXXXYBo4jmfsu7K0qJSFvu3nlVvYOcVz4GXXXXX') 
}); 

var params = { 
    IdentityPoolId: 'ap-northeast-2:a383cb2e-e302-4ff6-8d8f-70e3185XXXXX', 
    Logins: { 
     'com.abc.xyz': '' // different value for each user 
    } 
}; 

var cognitoidentity = new AWS.CognitoIdentity(); 
cognitoidentity.getOpenIdTokenForDeveloperIdentity(params, function(err, data) { 
    if (err) { 
     console.log(err, err.stack); // an error occurred 
    } 
    else { 
     console.log(data);   // successful response 
    } 
}); 

服務器結果:

IdentityId: "ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX" 
Token: "eyJra.....sL8bg" 

在瀏覽器:

AWS.config = new AWS.Config({ 
    region: 'ap-northeast-2' 
}); 

var params = { 
    IdentityId: 'ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX',  //Received from server 
    CustomRoleArn: 'arn:aws:iam::356127965XXX:role/XXXXX_Customer', 
    Logins: { 
     'com.abc.xyz': '' 
    } 
}; 

var cognitoidentity = new AWS.CognitoIdentity(); 
cognitoidentity.getCredentialsForIdentity(params, function(err, data) { 
    if (err) { 
     console.log(err, err.stack); // an error occurred 
    } 
    else { 
     console.log(data);   // successful response 
    } 
}); 

瀏覽器結果:

Please provide a valid public provider 

身份池配置 Identity Pool Configuration

回答

1

基礎上this post,我做了在瀏覽器中的部分如下更改現在

AWS.config.credentials = new AWS.CognitoIdentityCredentials({ 
    IdentityId: 'ap-northeast-2:5cf7f3cd-b370-416b-bed8-f7f8c7aXXXXX',  //Received from server 
IdentityPoolId: 'ap-northeast-2:a383cb2e-e302-4ff6-8d8f-70e3185XXXXX', 
    Logins: { 
     'cognito-identity.amazonaws.com': '' 
    } 
}); 

AWS.config.credentials.get(function(err, data) { 
    if (err) { 
     console.log(err); // an error occurred 
    } 
    else { 
     console.log(data);   // successful response 
    } 
}); 

AWS.config.credentials 

我能夠收到包含accessKeyId的響應,過期時間,secretAccessKey和sessionToken

相關問題