public CognitoAWSCredentials(string accountId, string identityPoolId, string unAuthRoleArn, string authRoleArn, IAmazonCognitoIdentity cibClient, IAmazonSecurityTokenService stsClient) { if (string.IsNullOrEmpty(identityPoolId)) { throw new ArgumentNullException("identityPoolId"); } if (cibClient == null) { throw new ArgumentNullException("cibClient"); } if ((unAuthRoleArn != null || authRoleArn != null) && stsClient == null) { throw new ArgumentNullException("stsClient"); } AccountId = accountId; IdentityPoolId = identityPoolId; UnAuthRoleArn = unAuthRoleArn; AuthRoleArn = authRoleArn; Logins = new Dictionary <string, string>(StringComparer.Ordinal); cib = (AmazonCognitoIdentityClient)cibClient; sts = (AmazonSecurityTokenServiceClient)stsClient; string cachedIdentityId = GetCachedIdentityId(); if (!string.IsNullOrEmpty(cachedIdentityId)) { UpdateIdentity(cachedIdentityId); currentState = GetCachedCredentials(); } }
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; }