How can I update a Cognito User Attribute from C# code using Hosted UI?

0

I'm using Cognito Hosted UI with a C# project i can get current user details, but i can't update the current user attributes. I'm on a track to find the solution. I believe using the UpdateUserAttributesAsync function from Amazon.CognitoIdentityProvider, but I'm not sure how to get the AccessToken from the UpdateUserAttributesRequest class. Would it be possible to guide me or tell me how to modify the attributes of a user?

AWSCredentials awsCredentials = new BasicAWSCredentials("accessKey", "secretKey");

AmazonCognitoIdentityProviderClient cognitoClient = new(awsCredentials);

UpdateUserAttributesRequest updateUserAttributesRequest = new()
{ 
     //AccessToken = Azure.Core.Token
 };

List<AttributeType> userAttributes = new()
{
       new AttributeType() { Name = "email", Value = "allo@test.com" },
       new AttributeType() { Name = "custom:PhoneNumber", Value = "888 888 8888" }
};

updateUserAttributesRequest.UserAttributes = userAttributes;
var testss = await cognitoClient.UpdateUserAttributesAsync(updateUserAttributesRequest);
질문됨 일 년 전1148회 조회
1개 답변
0
수락된 답변

Hi, i found my answer. You can get the accessToken from this function below and here is the link for stackoverflow answer. https://stackoverflow.com/questions/66258459/how-to-get-aws-cognito-access-token-with-username-and-password-in-net-core-3-1

public static async Task<string> GetCredsAsync()
        {
            AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), Amazon.RegionEndpoint.USEast1);
            CognitoUserPool userPool = new("", "", provider, "");
            CognitoUser user = new("", "", userPool, provider, "");
            InitiateSrpAuthRequest authRequest = new()
            {
                Password = ""
            };

            AuthFlowResponse authResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
            var accessToken = authResponse.AuthenticationResult.AccessToken;
            return accessToken;
        }
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인