3

私はAWSの認証されていない/匿名のユーザーアクセスに自分の足元を浸しており、生成されたトークンをラムダ経由でCognitoから取得したいと考えていました。ラムダのAWS Cognitoを.NET用に使用

私は次のエラーでラムダで実行することができませんでした。

This functionality is not implemented in the portable version of this assembly

{ 
    "errorType": "NotImplementedException", 
    "errorMessage": "This functionality is not implemented in the portable version of this assembly. You should reference the AWSSDK.Core NuGet package from your main application project in order to reference the platform-specific implementation.", 
    "stackTrace": [ 
    "at Amazon.Util.Internal.PlatformServices.ApplicationSettings.GetValue(String key, ApplicationSettingsMode mode)", 
    "at Amazon.CognitoIdentity.CognitoAWSCredentials.GetCachedIdentityId()", 
    "at Amazon.CognitoIdentity.CognitoAWSCredentials..ctor(String accountId, String identityPoolId, String unAuthRoleArn, String authRoleArn, IAmazonCognitoIdentity cibClient, IAmazonSecurityTokenService stsClient)", 
    "at Amazon.CognitoIdentity.CognitoAWSCredentials..ctor(String accountId, String identityPoolId, String unAuthRoleArn, String authRoleArn, RegionEndpoint region)", 
    "at AwsDotnetCsharp.AuthHandler.Get(APIGatewayProxyRequest request, ILambdaContext context)", 
    "at lambda_method(Closure , Stream , Stream , ContextInfo)" 
    ] 
} 

ラムダは、新しいC#のDOTNETコアバージョンではなく、JavaScriptがあります。私は

だからDOTNETコア(.NET標準1.6)writngの時にバージョン3.3.1.1であると(まだ)は互換性がありませんCognitoAWSCredentialsあるproject.jsonで(https://www.nuget.org/packages/AWSSDK.CognitoIdentity/)をAWSSDK.CoreとAWSSDK.SecurityTokenを参照していますそれがそうであると言うナゲットサイトで考えた。この作業を取得するためには何が必要です

マイラムダコードがされています...(右ではないかもしれないが、私はそれが前進するために実行するために取得することはできません)

public class AuthHandler 
    { 
     public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context) 
     { 
      CognitoAWSCredentials credentials = 
       new CognitoAWSCredentials("us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", Amazon.RegionEndpoint.USEast1); 

      var identityPoolId = credentials.GetIdentityIdAsync(); 

      AmazonCognitoIdentityClient cognitoClient = new AmazonCognitoIdentityClient(
       credentials, // the anonymous credentials 
       Amazon.RegionEndpoint.USEast1 // the Amazon Cognito region 
      ); 

      GetIdRequest idRequest = new GetIdRequest(); 
      idRequest.AccountId = "############"; 
      idRequest.IdentityPoolId = identityPoolId.Result; 

      var idResp = cognitoClient.GetIdAsync(idRequest); 

      var id = idResp.Result.IdentityId; 

      var response = new APIGatewayProxyResponse 
      { 
       StatusCode = (int)HttpStatusCode.OK, 
       Body = $"{{ \"{id}\" }}", 
       Headers = new Dictionary<string, string> { { "Content-Type", "application/json" } } 
      }; 

      return response; 
     } 
    } 

答えて

0

ここでの主な問題は、.net Framework 4.5と.net StandardのAWSSDK.CoreモジュールがAmazon.Util.Internal.PlatformServices.IApplicationSettingsインターフェイスを実装していないことです。例外メッセージは、Xamarin、Windows Phone、Windows Universalなどのプラットフォーム固有のバージョンでのみ実装されていることを示しています。 https://github.com/aws/aws-sdk-net/tree/master/sdk/src/Core/Amazon.Util/Internal/PlatformServices

CognitoAWSCredentialsオブジェクトを使用するのではなく、AmazonCognitoIdentityClientを直接呼び出して対処する必要があります。クライアントを使用してAWS IDを取得する

サンプルはhttps://aws.amazon.com/blogs/mobile/use-amazon-cognito-in-your-website-for-simple-aws-authentication/

// initialize a set of anonymous AWS credentials for our API calls 
AnonymousAWSCredentials cred = new AnonymousAWSCredentials(); 

// initialize the Cognito identity client and prepare a request object 
// to get the identity id 
AmazonCognitoIdentityClient cognitoClient = new AmazonCognitoIdentityClient(
    cred, // the anonymous credentials 
    RegionEndpoint.USEast1 // the Amazon Cognito region 
); 

GetIdRequest idRequest = new GetIdRequest(); 
idRequest.AccountId = "YOUR_AWS_ACCOUNT_ID"; 
idRequest.IdentityPoolId = "YOUR_COGNITO_IDENTITY_POOL_ID"; 
// set the Dictionary of logins if you are authenticating users 
// through an identity provider 
//idRequest.Logins = new Dictionary { 
// { "graph.facebook.com", "FacebookSessionToken" } 
//}; 

// The identity id is in the IdentityId parameter of the response object 
GetIdResponse idResp = cognitoClient.GetId (idRequest); 
である
関連する問題