0

我試圖在用戶服務器端簽署asp.net的Core 2登錄用戶/用戶進行身份驗證與AWS Cognito

我已經註冊了用戶,並驗證鏈接確認了,但現在我很努力簽署該用戶進入我的應用程序。遺憾的是,c#的文檔非常糟糕!

用戶池配置:

應用程序客戶端:啓用登錄基於服務器的身份驗證(ADMIN_NO_SRP_AUTH)API - 檢查

下面的代碼:

public async Task<bool> SignInUserAsync(CognitoUser user) 
    { 
     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; 
     } 


    } 

的錯誤回報是Missing Authentication Token,但我無法確定令牌需要設置/給予的位置。

它是下

AWS > User Pools > App Intergration > App Client Settings的東西與我的AmazonCognitoIdentityProviderClient設置或者是App客戶端的設置?

回答

0

AdminInitiateAuth API意味着從可以訪問開發人員IAM憑證的後端調用。既然你試圖用AnonymousAWSCredentials來調用這個,你會得到Missing Authentication Token錯誤。

Cognito用戶池尚未對C#提供本機支持。您應該使用hosted auth pages而不是本機API調用將Cognito用戶池集成到C#應用程序中。

相關問題