title: How to get AccessToken or Session string in WinUI 3 application to initiate set up of AWS Cognito MFA
body: <p>I am building WinUI 3 desktop app which uses AWS Cognito for user sign-up/sign-in and I came across a problem when trying to implement MFA set up after user creation.</p>
  <p>According to AWS documentation I need to call <code>AssociateSoftwareToken</code> with <code>AssociateSoftwareTokenRequest</code> parameter and its &quot;Access Token&quot; or &quot;Session String&quot; properties set to authorize the request:</p>
  <p><a href="https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CognitoIdentityProvider/MCognitoIdentityProviderAssociateSoftwareTokenAsyncAssociateSoftwareTokenRequestCancellationToken.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CognitoIdentityProvider/MCognitoIdentityProviderAssociateSoftwareTokenAsyncAssociateSoftwareTokenRequestCancellationToken.html</a></p>
  <p><a href="https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CognitoIdentityProvider/TAssociateSoftwareTokenRequest.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CognitoIdentityProvider/TAssociateSoftwareTokenRequest.html</a></p>
  <p>My question is - how can I get the AccessToken or Session string from my preceding sign-in request to then authorize <code>AssociateSoftwareToken</code> in WinUi 3 desktop app?</p>
  <p>I've googled around and read AWS and MS docs but cannot find anything helpful in this regard.</p>
  <p>My code snippets:</p>
  <ol>
  <li>User sign-in method:</li>
  </ol>
  <pre><code>        try
          {
              AmazonCognitoIdentityProviderClient provider = new(new AnonymousAWSCredentials(), FallbackRegionFactory.GetRegionEndpoint())
              CognitoUserPool cognitoUserPool = new(poolID, clientID, provider);
              CognitoUser cognitoUser = new(username, clientID, cognitoUserPool, provider);
              InitiateSrpAuthRequest authRequest = new()
              {
                  Password = password
              };
              AuthFlowResponse authFlowResponse = await cognitoUser.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);
  
              if (authFlowResponse.AuthenticationResult is null)
              {  
                  if (authFlowResponse.ChallengeName == ChallengeNameType.MFA_SETUP)
                  {
                     //At this point I need AccessToken or Session string to to call CognitoSetUpTOTPMFAAsync(string accessToken) to trigger MFA setup...
                  }
                  .
                  //remaining implementation
                  .
              }
              return ...
          }
          catch (Exception e)
          {
              return ...
          }
  </code></pre>
  <ol start="2">
  <li>CognitoSetUpTOTPMFAAsync(string accessToken OR string sessionString)</li>
  </ol>
  <pre><code>        try
          {
              
              AmazonCognitoIdentityProviderClient provider = new(new AnonymousAWSCredentials(), FallbackRegionFactory.GetRegionEndpoint());
              AssociateSoftwareTokenRequest associateSoftwareTokenRequest = new()
              {
                  AccessToken = accessToken,
                  Session = sessionString               
              };
              AssociateSoftwareTokenResponse associateSoftwareTokenResponse = await provider.AssociateSoftwareTokenAsync(associateSoftwareTokenRequest);
              .
              //remaining implementation
              .
              return ...
          }
          catch (Exception)
          {
              return ...
          }
  </code></pre>