Amazon.CognitoIdentity.AmazonCognitoIdentityClient.GetOpenIdTokenForDeveloperIdentity C# (CSharp) Method

GetOpenIdTokenForDeveloperIdentity() public method

Registers (or retrieves) a Cognito IdentityId and an OpenID Connect token for a user authenticated by your backend authentication process. Supplying multiple logins will create an implicit linked account. You can only specify one developer provider as part of the Logins map, which is linked to the identity pool. The developer provider is the "domain" by which Cognito will refer to your users.

You can use GetOpenIdTokenForDeveloperIdentity to create a new identity and to link new logins (that is, user credentials issued by a public provider or developer provider) to an existing identity. When you want to create a new identity, the IdentityId should be null. When you want to associate a new login with an existing authenticated/unauthenticated identity, you can do so by providing the existing IdentityId. This API will create the identity in the specified IdentityPoolId.

You must use AWS Developer credentials to call this API.

/// The provided developer user identifier is already registered with Cognito under a /// different identity ID. /// /// Thrown when the service encounters an error during processing the request. /// /// Thrown for missing or bad input parameter(s). /// /// Thrown when a user is not authorized to access the requested resource. /// /// Thrown when a user tries to use a login which is already linked to another account. /// /// Thrown when the requested resource (for example, a dataset or record) does not exist. /// /// Thrown when a request is throttled. ///
public GetOpenIdTokenForDeveloperIdentity ( GetOpenIdTokenForDeveloperIdentityRequest request ) : GetOpenIdTokenForDeveloperIdentityResponse
request GetOpenIdTokenForDeveloperIdentityRequest Container for the necessary parameters to execute the GetOpenIdTokenForDeveloperIdentity service method.
return GetOpenIdTokenForDeveloperIdentityResponse
        public GetOpenIdTokenForDeveloperIdentityResponse GetOpenIdTokenForDeveloperIdentity(GetOpenIdTokenForDeveloperIdentityRequest request)
        {
            var marshaller = new GetOpenIdTokenForDeveloperIdentityRequestMarshaller();
            var unmarshaller = GetOpenIdTokenForDeveloperIdentityResponseUnmarshaller.Instance;

            return Invoke<GetOpenIdTokenForDeveloperIdentityRequest,GetOpenIdTokenForDeveloperIdentityResponse>(request, marshaller, unmarshaller);
        }

Usage Example

        private CognitoCredential LetUsDealWithTheAWSCognitoIDStuff(String userID)
        {
            String AccessKey = ConfigurationManager.AppSettings["AWSAccessKeyId"];
               String SecretAccessKey = ConfigurationManager.AppSettings["AWSSecretAccessKey"];
               BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(AccessKey, SecretAccessKey);

               AmazonCognitoIdentityConfig config = new AmazonCognitoIdentityConfig();
               config.ServiceURL = "ec2.us-east-1.amazonaws.com";
               config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;

               AmazonCognitoIdentityClient identityClient = new AmazonCognitoIdentityClient(basicAWSCredentials, config);

               GetOpenIdTokenForDeveloperIdentityRequest idRequest = new GetOpenIdTokenForDeveloperIdentityRequest();
               idRequest.IdentityPoolId = "us-east-1:c812ebc0-88e3-44d9-84e4-8e2ac888d19f";

               Dictionary<string, string> userLogins =  new Dictionary<string, string>();
               userLogins.Add("Login.WhatsNowWebService", userID);
               idRequest.Logins = userLogins;

               idRequest.TokenDuration = 60 * 5;
               GetOpenIdTokenForDeveloperIdentityResponse idResp = identityClient.GetOpenIdTokenForDeveloperIdentity(idRequest);

               string cognitoId = idResp.IdentityId;
               string oidToken = idResp.Token;

               CognitoCredential cc = new CognitoCredential();
               cc.CognitoID = cognitoId;
               cc.CognitoToken = oidToken;

               return cc;
        }
AmazonCognitoIdentityClient