亚马逊cognito:身份未找到 [英] Amazon cognito: identity not found

查看:835
本文介绍了亚马逊cognito:身份未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的开发者认证project.And我试图让c.But它给我下面的错误使用这种低于$ C $凭据。

I am working on developer authenticated project.And I am trying to get credentials using this below code.But it is giving me following error.

我已经粘贴IdentityId和令牌进入手动从服务器code此code:

I have pasted IdentityId and Token manually into this code from server code:

    Caused by: com.amazonaws.services.cognitoidentity.model.ResourceNotFoundException: Identity 'ap-northeast-1:fe81cd76-e9d4-4416-99ea-b684b78743c8' not found. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: 2ac65fe8-d41a-11e5-8674-677eefdb5331)
                                                 at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:709)
                                                 at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:385)
                                                 at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)
                                                 at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:533)
                                                 at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getCredentialsForIdentity(AmazonCognitoIdentityClient.java:406)
                                                 at com.example.sandesh.aws.MainActivity$network.doInBackground(MainActivity.java:101)
                                                 at com.example.sandesh.aws.MainActivity$network.doInBackground(MainActivity.java:52)
                                                 at android.os.AsyncTask$2.call(AsyncTask.java:292)

下面是我的code:MainActivity.java

Here is my code: MainActivity.java

    public class MainActivity extends AppCompatActivity {

Button button;

protected static CognitoCachingCredentialsProvider credentialsProvider = null;
private GetCredentialsForIdentityResult credentialsForIdentityResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    button = (Button)findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            network net = new network();
            net.execute();
        }
    });
}
public class network extends AsyncTask<Void,Void,String>{
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(Void... params) {

        Authentication developerProvider = new Authentication(
                null,
                "ap-northeast-1:XXXXXXXXXXXXXXXXXX",
                Regions.AP_NORTHEAST_1);

        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(),
                developerProvider,
                Regions.AP_NORTHEAST_1);


        HashMap<String, String> loginsMap = new HashMap<String, String>();
        loginsMap.put(developerProvider.getProviderName(), "7386372772");
        credentialsProvider.setLogins(loginsMap);
        credentialsProvider.refresh();
        GetCredentialsForIdentityRequest credentialsForIdentityRequest = new GetCredentialsForIdentityRequest();

        credentialsForIdentityRequest.setIdentityId(developerProvider.getIdentityId());
        credentialsForIdentityRequest.setLogins(loginsMap);
        AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient(credentialsProvider);
        credentialsForIdentityResult = cognitoIdentityClient.getCredentialsForIdentity(credentialsForIdentityRequest);

        Log.d("access_key",credentialsForIdentityResult.getCredentials().getAccessKeyId());
        return credentialsForIdentityResult.getCredentials().getAccessKeyId();
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
    }
}}

Authentication.java

Authentication.java

   public class Authentication extends AWSAbstractCognitoDeveloperIdentityProvider {


private static final String PROVIDERNAME = "login.blupinch.app";
public String response = " ";
String line = " ";
public Authentication(String accountId, String identityPoolId, Regions region) {
    super(accountId, identityPoolId, region);
}

@Override
public String getProviderName() {
    return PROVIDERNAME;
}
public String refresh() {

    setToken(null);

    if (getProviderName() != null &&
            !this.loginsMap.isEmpty() &&
            this.loginsMap.containsKey(getProviderName())) {

        update(identityId, token);
        return "eyJraWQiOiJhcC1ub3J0aGVhc3QtMTEiLCJ0eXAiOiJKV1MiLCJhbGciOiJSUzUxMiJ9.eyJzdWIiOiJhcC1ub3J0aGVhc3QtMTpmZTgxY2Q3Ni1lOWQ0LTQ0MTYtOTllYS1iNjg0Yjc4NzQzYzgiLCJhdWQiOiJhcC1ub3J0aGVhc3QtMTphODcxZmE1Zi0yM2EyLTQ4MGQtYmFhNi1iNGVkMzE0MzcyNDQilCJhbXIiOlsiYXV0aGVudGljYXRlZCIsImxvZ2luLmJsdXBpbmNoLmFwcCIsImxvZ2luLmJsdXBpbmNoLmFwcDphcC1ub3J0aGVhc3QtMTphODcxZmE1Zi0yM2EyLTQ4MGQtYmFhNi1iNGVkMzE0MzcyNDQ6NzM4NjM3Mjg3MiJdLCJpc3MiOiJodHRwczovL2NvZ25pdG8taWRlbnRpdHkuYW1hem9uYXdzLmNvbSIsImV4cCI6MTQ1NTU5NTM5NywiaWF0IjoxNDU1NTU5Mzk3fQ.fHHH6aeCn5EaJGxGD6tw7bWyQpPHuYcW8SZLRGVn-3cbamJrWEPmUnNvcLJ-D6nL8AvMQy7-s1LGQ5MNaiuIH7QF6W8aWt2OMALmA_Y7eqpGQ6iQXVma_jTZSpiyBe2cPNggWgeslPtFxomwE90vW0rzS1sY3D5Y3UbnrIHNdiPKIzzP9JaQo1IsTJMKEpQM-jzWP6stV1radDuIzWQroBVQseOQSD-MXV_-cgWWSx0eQmtFbjJW6RP_nACgh0uTbGmMuOi2iKXKQAdGlYWO-PHlShbiHT-WLQoZNWuh95Hh9dMldv-mNdnYSblqYyqptLA3kObioI08XXkTqwaaAw";


    } else {
        this.getIdentityId();
        return null;
    }
}
public String getIdentityId() {

    identityId = "ap-northeast-1:XXXXXXXXXXXXXXXXXXXXXXXX";

    if (identityId == null) {


        if (getProviderName() != null && !this.loginsMap.isEmpty()
                && this.loginsMap.containsKey(getProviderName())) {

            update(identityId, token);
            return "ap-northeast-1:XXXXXXXXXXXXXXXXXXXX";

        } else {
            return super.getIdentityId();
        }

    } else {
        return identityId;
    }

}}

我在PHP,我进行getOpenIdTokenForDeveloperIdentity,stsClient和AssumerolewithWebIdentity得到凭据它的工作很大的尝试。先谢谢你。

I have tried it in PHP where I performed getOpenIdTokenForDeveloperIdentity , stsClient and AssumerolewithWebIdentity to get credentials it worked great. Thank you in advance.

推荐答案

在使用开发者验证的身份,登录名映射呼叫<一个href=\"https://mobile.awsblog.com/post/Tx2323YHCM0I7OO/Understanding-Amazon-Cognito-Authentication-Part-4-Enhanced-Flow\"相对=nofollow> GetCredentialsForIdentity 应该有cognito-identity.amazonaws.com为重点,而不是开发商提供程序名称。

When using Developer Authenticated Identities, the logins map for the call GetCredentialsForIdentity should have "cognito-identity.amazonaws.com" as the key instead of developer provider name.

此外,你不应该自己调用此方法,SDK将照顾这。

Also, you should not be calling this method yourself, the SDK will take care of this.

更新:

当调用getCredentialsForIdentity,在登录映射时,关键是cognito-identity.amazonaws.com,该值应该是您从后端调用了之后GetOpenIdTokenForDeveloperIdentity令牌。你并不需要获得凭据做AWS业务,只是这个凭据提供初始化AWS服务客户端,你应该是好去。

When calling getCredentialsForIdentity, in the logins map, when key is "cognito-identity.amazonaws.com", the value should be the token you got from your backend after calling GetOpenIdTokenForDeveloperIdentity. You do not need to get the credentials for doing AWS operations, just initialize the AWS Service Client with this credentials provider and you should be good to go.

这篇关于亚马逊cognito:身份未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆