2017-05-20 3 views
0

Ich versuche, die verbesserte vereinfachte Authentifizierungsablauf beschrieben auf AWS docsCognito: Wie richtig verbesserte vereinfachte Authentifizierungsablauf implementieren

enter image description here

Problem zu bekommen, ist ich kann nicht herausfinden, wie man richtig das SDK verwenden. ..

AWS.config.region = "ap-northeast-2" 
    const cognitoParams = { 
    IdentityPoolId: "ap-northeast-2:...", 
    Logins: { 
     "accounts.google.com": googleUser.getAuthResponse().id_token 
    } 
    } 
    AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams) 

    const identity = new AWS.CognitoIdentity() 
    identity.getId(cognitoParams, function (err, identityId) { 
    console.log(identityId) 

    const identityParams = Object.assign({}, cognitoParams, { 
     IdentityId: identityId 
    }) 

    identity.getCredentialsForIdentity(identityParams, function (err, data) { 
     console.log(data) 
    }) 
    }) 

Das 2 console.log gibt null

AWS.config.region = "ap-northeast-2" 
const cognitoParams = { 
    IdentityPoolId: "ap-northeast-2:31cc246c-bd2e-46ee-91da-2b8eefcf0745", 
    Logins: { 
    "accounts.google.com": googleUser.getAuthResponse().id_token 
    } 
} 
AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams) 

AWS.config.credentials.getId(function (err, identityId) { 
    console.log(identityId) 

    const identityParams = Object.assign({}, cognitoParams, { 
    IdentityId: identityId 
    }) 

    AWS.config.credentials.getCredentialsForIdentity(identityParams, function (err, data) { 
    console.log(data) 
    }) 
}) 

Das obige gibt mir die Identität aber schlägt mit Cannot read property 'getCredentialsForIdentity' of undefined fehl.

Wie implementiere ich das?

Antwort

0

Ich fand, dass das unten funktioniert ... Ich sollte Funktionen von einer Instanz von CognitoIdentity anstelle von CognitoIdentityCredentials aufrufen ... aber es ist nicht klar in den Dokumentationen.

Tatsächlich verwendet CognitoIdentityCredentials und Grund dafür? Wann verwende ich beides?

AWS.config.region = "ap-northeast-2" 
    const cognitoParams = { 
    IdentityPoolId: "ap-northeast-2:31cc246c-bd2e-46ee-91da-2b8eefcf0745", 
    Logins: { 
     "accounts.google.com": googleUser.getAuthResponse().id_token 
    } 
    } 
    // AWS.config.credentials = new AWS.CognitoIdentityCredentials(cognitoParams) 

    const identity = new AWS.CognitoIdentity() 
    identity.getId(cognitoParams, function (err, identityData) { 
    if (err) { 
     return console.error(err) 
    } 

    const identityParams = { 
     IdentityId: identityData.IdentityId, 
     Logins: cognitoParams.Logins 
    } 

    identity.getCredentialsForIdentity(identityParams, function (err, data) { 
     if (err) { 
     return console.error(err) 
     } 
     console.log(data) 
    }) 
+0

Was ist "googleUser"? –

Verwandte Themen