I need to expose an api, which also allows us to get the scope, but I'm failing with all my attempts using aws cognito.
So I was hoping to do the following:
- assign scope:foo to existing users and new users
- get an access token back containing that scope of foo (using c# back end code)
Part I: Getting Access Token with Scope
So for getting a token it's the following:
var provider = new AmazonCognitoIdentityProviderClient(new BasicAWSCredentials(AccessKey, SecretKey));
var request1 = new AdminInitiateAuthRequest
{
UserPoolId = userPoolId,
ClientId = request.ClientId,
AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH,
AuthParameters =
{
{"USERNAME", request.UserName},
{"PASSWORD", request.Password}
}
};
var response1 = await provider.InitiateAuthAsync(request);
Now, I can gain the tokens with this request/response (obviously with good credentials :) ). What I cannot figure out is how to ask for more scope items. Currently it only returns aws.cognito.signin.user.admin
Part II: User Attributes
With that said, I've also added a custom:some-attribute attribute. I can see it within UI for the General settings \ Attributes screen. I don't have any lambda triggers setup, BTW.
I'm finding that I can update the user settings, as I get an OK|200 status returned, but if I try and get the user, his updated attribute doesn't show up.
var request2 = new AdminUpdateUserAttributesRequest
{
UserAttributes = new List<AttributeType>
{
new AttributeType {
Name="custom:some-attribute",
Value=Guid.NewGuid().ToString("N")
};
UserPoolId = userPoolId,
Username = userName
};
var response2 = await provider.AdminUpdateUserAttributesAsync(request);
Later I go to look up the user:
var result = await _provider.GetUserAsync(new GetUserRequest
{
AccessToken = response1.AuthenticationResult.AccessToken
});
... my newly updated variable doesn't show in the result.UserAttribues AttributeType list.
Maybe I'm doing this wrong, but I cannot figure out how to create a scope (which I was thinking I could do an alternative via the custom attribute) and get the scope.
Equally, I cannot figure out how to pass in a scope when authenticating for tokens.
Thanks, Kelly