如何从Xamarin Forms

时间:2017-01-03 18:22:02

标签: xamarin amazon-dynamodb amazon-cognito

我正在创建一个允许用户使用AWS Cognito通过Facebook登录的移动应用程序。处理它的代码看起来像这样。

public async Task FacebookCongitoLogin(FacebookProfile profile)
{

        config = new AmazonCognitoSyncConfig { RegionEndpoint = RegionEndpoint.USEast1 };
        creds = new CognitoAWSCredentials("ARN_ID_STUFF", RegionEndpoint.USEast1);
        creds.AddLogin("graph.facebook.com", MySettings.FBToken);

        syncManager = new CognitoSyncManager(creds, config);

        await creds.GetCredentialsAsync();

        Content = null;
        saveProfileInfo(profile);
 }

private void saveProfileInfo(FacebookProfile profile)
{
    Dataset profileData = syncManager.OpenOrCreateDataset("fb_profile");
                profileData.OnSyncSuccess += SyncSuccessCallback;
                profileData.OnSyncFailure += SyncFailureCallback;
    profileData.Put("fb_profile",JsonConvert.SerializeObject(profile));
                profileData.SynchronizeAsync();
}

在我登录用户之后,我试图将对象安全地保存到我新创建的DynamoDB表中。

using System;
using System.Threading.Tasks;
using Amazon;
using Amazon.CognitoIdentity;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;

namespace TechPact
{
    public class CreateInviteAction
    {
        private CognitoAWSCredentials creds;
        public CreateInviteAction()
        {
            var token = TechPactSettings.FBToken;
            creds = new CognitoAWSCredentials("ARN_ID_KEY", RegionEndpoint.USEast1);
            creds.AddLogin("graph.facebook.com", token);
            creds.GetCachedCredentials();

        }

        public async Task execute(Invite invite)
        {
            var client = new AmazonDynamoDBClient(creds, RegionEndpoint.USEast1);
            var context = new DynamoDBContext(client);

            await context.SaveAsync(invite);

        }
    }
}

当上面的操作运行时,我得到一个AmazonDynamoDBException User:arn:aws:sts::123234234:assumedrole/inviteapp_auth_MOBILEHUB_1232342345/CognitoIdentityCredentials is not authorized to preform: dynamodb:DescribeTable on resource: arn:aws:dynamodb:us-ease-1:1232314234:table/Invite

这是我为用户池创建的自定义角色警察。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:*"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-east-1:12312312312:table/invite-mobilehub-234234234-Invite"
            ],
            "Condition": {
                "ForAllValues:StringEquals": {
                    "dynamodb:LeadingKeys": [
                        "${graph.facebook.com:id}"
                    ]
                }
            }
        }
    ]
}

0 个答案:

没有答案