Anbarasi Anbarasi - 3 months ago 54
C# Question

Error : The security token included in the request is invalid - Windows Phone Using AWS SNS

I am using below code to register the device(Windows Phone) in AWS SNS as an endpoint in the application

CognitoAWSCredentials cognitoProvider = new CognitoAWSCredentials(UserId,
IdentitypoolID,
UnAuthRoleARN,
AuthRoleARN,
Region);

AmazonSimpleNotificationServiceClient sns = new AmazonSimpleNotificationServiceClient(cognitoProvider.GetCredentials().AccessKey.ToString(),
cognitoProvider.GetCredentials().SecretKey.ToString(), REgion); //provide credentials here

var channelOperation = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

CreatePlatformEndpointRequest epReq = new CreatePlatformEndpointRequest();
epReq.PlatformApplicationArn = ApplicationArn;
epReq.Token = channelOperation.Uri.ToString();

CreatePlatformEndpointResponse epRes = await sns.CreatePlatformEndpointAsync(epReq);

CreateTopicRequest tpReq = new CreateTopicRequest();

SubscribeResponse subsResp = await sns.SubscribeAsync(new SubscribeRequest()
{
TopicArn = TopicArn,
Protocol = "application",
Endpoint = epRes.EndpointArn
});


While create an endpoint it throws an error The security token included in the request is invalid while execute below code

CreatePlatformEndpointResponse epRes = await sns.CreatePlatformEndpointAsync(epReq);


Please help me to achieve this. Thanks in advance

Answer

Use the below code to register a windows phone device in AWS SNS Application. I can create endpoint using the below code.

private async void Push()
        {
            CognitoAWSCredentials cognitoProvider = new CognitoAWSCredentials(UserId,
                   IdentitypoolID,
                   UnAuthRoleARN,
                   AuthRoleARN,
                   Region);

            using (var sns = new AmazonSimpleNotificationServiceClient(credentials, RegionEndpoint.USEast1))
            {
                var channelOperation = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

                CreatePlatformEndpointRequest epReq = new CreatePlatformEndpointRequest();
                epReq.PlatformApplicationArn = "PlatformApplicationARN";
                epReq.Token = channelOperation.Uri.ToString();

                CreatePlatformEndpointResponse epRes = await sns.CreatePlatformEndpointAsync(epReq);

                CreateTopicRequest tpReq = new CreateTopicRequest();

                SubscribeResponse subsResp = await sns.SubscribeAsync(new SubscribeRequest()
                {
                    TopicArn = "TopicARN",
                    Protocol = "application",
                    Endpoint = epRes.EndpointArn
                });

                channelOperation.PushNotificationReceived += ChannelOperation_PushNotificationReceived;
            }
        }
Comments