Question:
I am trying to sign in a user server side on asp.net Core 2
I have registered a user and confirmed with a verification link but now I am struggling to sign that user into my application. It’s a shame the documentation for c# is so poor!
User Pool Config:
App Client: Enable sign-in API for server-based authentication (ADMIN_NO_SRP_AUTH) – checked
Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public async Task { var provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), RegionEndpoint.GetBySystemName("eu-west-2")); try { var authReq = new AdminInitiateAuthRequest { AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH, UserPoolId = _poolId, ClientId = _clientId }; authReq.AuthParameters.Add("USERNAME", user.Email); authReq.AuthParameters.Add("PASSWORD", user.Password); AdminInitiateAuthResponse authResp = await provider.AdminInitiateAuthAsync(authReq); return true; } catch { return false; } } |
The error that returns is Missing Authentication Token
but I can’t work out where the token needs to be set / has been given to me.
Is it something with my AmazonCognitoIdentityProviderClient
settings or perhaps App client settings under the
AWS > User Pools > App Intergration > App Client Settings
?
Answer:
AdminInitiateAuth API is meant to be called from a back end which has access to developers IAM credentials. Since you are trying to call this with AnonymousAWSCredentials
, you are getting Missing Authentication Token
error.
Cognito User Pools does not yet have native support for C#. You should integrate Cognito User Pools in your C# app using the hosted auth pages instead of native API calls.