예제 #1
0
        internal GetIdResponse GetId(GetIdRequest request)
        {
            GetIdRequestMarshaller    marshaller = new GetIdRequestMarshaller();
            GetIdResponseUnmarshaller instance   = GetIdResponseUnmarshaller.Instance;

            return(Invoke <GetIdRequest, GetIdResponse>(request, marshaller, instance));
        }
예제 #2
0
        /// <summary>
        /// Generates (or retrieves) a Cognito ID. Supplying multiple logins will create an implicit
        /// linked account.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetId service method.</param>
        ///
        /// <returns>The response from the GetId service method, as returned by CognitoIdentity.</returns>
        /// <exception cref="InternalErrorException">
        /// Thrown when the service encounters an error during processing the request.
        /// </exception>
        /// <exception cref="InvalidParameterException">
        /// Thrown for missing or bad input parameter(s).
        /// </exception>
        /// <exception cref="LimitExceededException">
        /// Thrown when the total number of user pools has exceeded a preset limit.
        /// </exception>
        /// <exception cref="NotAuthorizedException">
        /// Thrown when a user is not authorized to access the requested resource.
        /// </exception>
        /// <exception cref="ResourceConflictException">
        /// Thrown when a user tries to use a login which is already linked to another account.
        /// </exception>
        /// <exception cref="ResourceNotFoundException">
        /// Thrown when the requested resource (for example, a dataset or record) does not exist.
        /// </exception>
        /// <exception cref="TooManyRequestsException">
        /// Thrown when a request is throttled.
        /// </exception>
        public GetIdResponse GetId(GetIdRequest request)
        {
            var marshaller   = new GetIdRequestMarshaller();
            var unmarshaller = GetIdResponseUnmarshaller.Instance;

            return(Invoke <GetIdRequest, GetIdResponse>(request, marshaller, unmarshaller));
        }
예제 #3
0
        public override void RefreshAsync(AmazonServiceCallback callback, object state)
        {
            //_token = null;
            AmazonServiceResult voidResult = new AmazonServiceResult(null, state);

            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = null,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };
                cib.GetIdAsync(getIdRequest, delegate(AmazonServiceResult result)
                {
                    if (result.Exception != null)
                    {
                        voidResult.Exception = result.Exception;
                        AmazonMainThreadDispatcher.ExecCallback(callback, voidResult);
                        return;
                    }
                    var getIdResponse = result.Response as GetIdResponse;
                    UpdateIdentity(getIdResponse.IdentityId);
                    AmazonMainThreadDispatcher.ExecCallback(callback, voidResult);
                }, null);
            }
            else
            {
                AmazonMainThreadDispatcher.ExecCallback(callback, voidResult);
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the Identity Id corresponding to the credentials retrieved from Cognito.
        /// Note: this setting may change during execution. To be notified of its
        /// new value, attach a listener to IdentityChangedEvent
        /// </summary>
        public string GetIdentityId()
        {
            if (!IsIdentitySet)
            {
                var cachedIdentityId = this.GetCachedIdentityId();
                if (string.IsNullOrEmpty(cachedIdentityId))
                {
                    var getIdRequest = new GetIdRequest
                    {
                        AccountId      = AccountId,
                        IdentityPoolId = IdentityPoolId,
                        Logins         = Logins
                    };
#if BCL
                    var response = cib.GetId(getIdRequest);
#else
                    var response = Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync <GetIdResponse>(() => cib.GetIdAsync(getIdRequest));
#endif

                    UpdateIdentity(response.IdentityId, true);
                }
                else
                {
                    UpdateIdentity(cachedIdentityId, false);
                }
            }

            return(identityId);
        }
예제 #5
0
        /// <summary>
        /// Gets the Identity Id corresponding to the credentials retrieved from Cognito.
        /// Note: this setting may change during execution. To be notified of its
        /// new value, attach a listener to IdentityChangedEvent
        /// </summary>
        public async System.Threading.Tasks.Task <string> GetIdentityIdAsync()
        {
            if (!IsIdentitySet)
            {
                var cachedIdentityId = this.GetCachedIdentityId();
                if (string.IsNullOrEmpty(cachedIdentityId))
                {
                    var getIdRequest = new GetIdRequest
                    {
                        AccountId      = AccountId,
                        IdentityPoolId = IdentityPoolId,
                        Logins         = Logins
                    };

                    var getIdResult = await cib.GetIdAsync(getIdRequest);

                    UpdateIdentity(getIdResult.IdentityId, true);
                }
                else
                {
                    UpdateIdentity(cachedIdentityId, false);
                }
            }

            return(identityId);
        }
예제 #6
0
        public static string CreateIdentity(string poolId, string poolName)
        {
            if (string.IsNullOrEmpty(TestAccountId))
            {
                Assert.Fail("TestAccountId must be specified to run these tests");
            }

            var identities = GetAllIdentities(poolId);

            Assert.IsNotNull(identities);
            int identitiesCount = identities.Count;

            var request = new GetIdRequest
            {
                IdentityPoolId = poolId,
                AccountId      = TestAccountId
            };
            var identityId = Client.GetId(request).IdentityId;

            Assert.IsFalse(string.IsNullOrEmpty(identityId));

            identities = GetAllIdentities(poolId);
            Assert.IsNotNull(identities);
            Assert.AreEqual(identitiesCount + 1, identities.Count);

            return(identityId);
        }
        IAsyncResult invokeGetId(GetIdRequest request, AsyncCallback callback, object state, bool synchronized)
        {
            var marshaller   = new GetIdRequestMarshaller();
            var unmarshaller = GetIdResponseUnmarshaller.Instance;

            return(Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer));
        }
예제 #8
0
        private void RefreshIdentityWebGL(Action <IdentityState> callback)
        {
            bool isCached = true;

            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };

                cib.GetIdAsync(getIdRequest, result =>
                {
                    isCached = false;
                    UpdateIdentity(result.Response.IdentityId);

                    callback(new IdentityState(identityId, isCached));
                });
            }
            else
            {
                callback(new IdentityState(identityId, isCached));
            }
        }
예제 #9
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetId operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity.GetId"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetId operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <GetIdResponse> GetIdAsync(GetIdRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetIdRequestMarshaller();
            var unmarshaller = GetIdResponseUnmarshaller.GetInstance();

            return(Invoke <IRequest, GetIdRequest, GetIdResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
예제 #10
0
        public async Task <IActionResult> ConnectToAWSViaCognitoCredsAsync()
        {
            try
            {
                if (!this.HttpContext.User.Identity.IsAuthenticated)
                {
                    return(new OkObjectResult("you have to sign in to access AWS resources"));
                }


                AnonymousAWSCredentials cred = new AnonymousAWSCredentials();

                AmazonCognitoIdentityClient cognitoClient = new AmazonCognitoIdentityClient(
                    cred,
                    RegionEndpoint.USEast2
                    );

                GetIdRequest idRequest = new GetIdRequest();
                idRequest.AccountId      = "628654266155";
                idRequest.IdentityPoolId = "us-east-2:c6e1e652-eb33-4daa-a04e-9cb0418a92cc";
                var logins = new Dictionary <string, string> {
                    { "dev-220949.okta.com/oauth2/default", GetOktaTokenMiddleware.OktaToken }
                };
                idRequest.Logins = logins;


                // The identity id is in the IdentityId parameter of the response object
                GetIdResponse idResp = await cognitoClient.GetIdAsync(idRequest);


                //GetCredentialsForIdentityRequest getCredentialsRequest =
                //    new GetCredentialsForIdentityRequest { IdentityId = idResp.IdentityId, Logins = logins };

                var temporaryCreds = await cognitoClient.GetCredentialsForIdentityAsync(idResp.IdentityId, logins);

                //var s3Client = new AmazonS3Client(temporaryCreds.Credentials, RegionEndpoint.USEast2);

                var s3Client = new AmazonS3Client(temporaryCreds.Credentials, RegionEndpoint.USEast2);

                return(await this.ObjectFromBucket(s3Client));

                //var assumeRoleRequest = new AssumeRoleWithWebIdentityRequest
                //{
                //    RoleArn = "arn:aws:iam::628654266155:role/acme_empoyees_accessing_s3",
                //    RoleSessionName = "testsession",
                //    WebIdentityToken = GetOktaTokenMiddleware.OktaToken,
                //};

                //var stsServiceClient = new AmazonSecurityTokenServiceClient(temporaryCreds.Credentials, RegionEndpoint.USEast2);
                //var response = await stsServiceClient.AssumeRoleWithWebIdentityAsync(assumeRoleRequest);

                //return new OkObjectResult($" assumed role is {response.AssumedRoleUser.AssumedRoleId}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #11
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetId operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetId operation on AmazonCognitoIdentityClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetId
        ///         operation.</returns>
        public IAsyncResult BeginGetId(GetIdRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new GetIdRequestMarshaller();
            var unmarshaller = GetIdResponseUnmarshaller.Instance;

            return(BeginInvoke <GetIdRequest>(request, marshaller, unmarshaller,
                                              callback, state));
        }
예제 #12
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetId operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetId operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <GetIdResponse> GetIdAsync(GetIdRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetIdRequestMarshaller();
            var unmarshaller = GetIdResponseUnmarshaller.Instance;

            return(InvokeAsync <GetIdRequest, GetIdResponse>(request, marshaller,
                                                             unmarshaller, cancellationToken));
        }
예제 #13
0
        public override Task <GetIdResponse> GetId(GetIdRequest request, ServerCallContext context)
        {
            var watchpoint = watchpointStore.GetObject(request.Watchpoint.Id);

            return(Task.FromResult(new GetIdResponse
            {
                Id = watchpoint.GetId()
            }));
        }
예제 #14
0
        /// <summary>
        /// Generates (or retrieves) a Cognito ID. Supplying multiple logins will create an implicit
        /// linked account.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetId service method.</param>
        ///
        /// <returns>The response from the GetId service method, as returned by CognitoIdentity.</returns>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.InternalErrorException">
        /// Thrown when the service encounters an error during processing the request.
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.InvalidParameterException">
        /// Thrown for missing or bad input parameter(s).
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.LimitExceededException">
        /// Thrown when the total number of user pools has exceeded a preset limit.
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.NotAuthorizedException">
        /// Thrown when a user is not authorized to access the requested resource.
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.ResourceConflictException">
        /// Thrown when a user tries to use a login which is already linked to another account.
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.ResourceNotFoundException">
        /// Thrown when the requested resource (for example, a dataset or record) does not exist.
        /// </exception>
        /// <exception cref="T:Amazon.CognitoIdentity.Model.TooManyRequestsException">
        /// Thrown when a request is throttled.
        /// </exception>
        public GetIdResponse GetId(GetIdRequest request)
        {
            var task = GetIdAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
예제 #15
0
        public Task <TUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
        {
            GetIdRequest r = new GetIdRequest();

            r.AccountId      = "919173020320";
            r.IdentityPoolId = "ap-southeast-2:67c062aa-1a19-49da-b30c-8a5b0f2287f2";
            r.Logins.Add("accounts.google.com", loginProvider);

            var t = _identityPoolClient.GetIdAsync(r).Result;

            //Amazon.CognitoIdentity.CognitoAWSCredentials creds=new CognitoIdentity.CognitoAWSCredentials("")


            throw new NotImplementedException();
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetId operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetId operation.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// <returns>void</returns>
        public void GetIdAsync(GetIdRequest request, AmazonServiceCallback callback, object state)
        {
            if (!AmazonInitializer.IsInitialized)
            {
                throw new Exception("AWSPrefab is not added to the scene");
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
            {
                var marshaller   = new GetIdRequestMarshaller();
                var unmarshaller = GetIdResponseUnmarshaller.Instance;
                Invoke(request, callback, state, marshaller, unmarshaller, signer);
            }));
            return;
        }
예제 #17
0
        public void GetIdAsync(GetIdRequest request, AmazonServiceCallback <GetIdRequest, GetIdResponse> callback, AsyncOptions options = null)
        {
            options = ((options == null) ? new AsyncOptions() : options);
            GetIdRequestMarshaller    marshaller = new GetIdRequestMarshaller();
            GetIdResponseUnmarshaller instance   = GetIdResponseUnmarshaller.Instance;
            Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;

            if (callback != null)
            {
                callbackHelper = delegate(AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao)
                {
                    AmazonServiceResult <GetIdRequest, GetIdResponse> responseObject = new AmazonServiceResult <GetIdRequest, GetIdResponse>((GetIdRequest)req, (GetIdResponse)res, ex, ao.State);
                    callback(responseObject);
                };
            }
            BeginInvoke(request, marshaller, instance, options, callbackHelper);
        }
예제 #18
0
        protected virtual IdentityState RefreshIdentity()
        {
            bool fromCache = true;

            if (!IsIdentitySet)
            {
                GetIdRequest request = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };
                GetIdResponse id = cib.GetId(request);
                fromCache = false;
                UpdateIdentity(id.IdentityId);
            }
            return(new IdentityState(identityId, fromCache));
        }
        /// <summary>
        /// Gets the Identity Id corresponding to the credentials retrieved from Cognito.
        /// Note: this setting may change during execution. To be notified of its
        /// new value, attach a listener to IdentityChangedEvent
        /// </summary>
        public async System.Threading.Tasks.Task <string> GetIdentityIdAsync()
        {
            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };

                var getIdResult = await cib.GetIdAsync(getIdRequest);

                UpdateIdentity(getIdResult.IdentityId, true);
            }

            return(identityId);
        }
        /// <summary>
        /// Provides a way to override fetching the identity in case of developer authenticated identities.
        /// The default behaviour will be using Cognito to retrieve the identity id.
        /// </summary>
        /// <returns>returns a <see cref="IdentityState"/></returns>
        public virtual async System.Threading.Tasks.Task <IdentityState> RefreshIdentityAsync()
        {
            bool isCached = true;

            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };
                var response = await cib.GetIdAsync(getIdRequest).ConfigureAwait(false);

                isCached = false;
                UpdateIdentity(response.IdentityId);
            }
            return(new IdentityState(identityId, isCached));
        }
        /// <summary>
        /// Provides a way to override fetching the identity in case of developer authenticated identities.
        /// The default behaviour will be using Cognito to retrieve the identity id.
        /// </summary>
        /// <returns>returns a <see cref="IdentityState"/></returns>
        protected virtual IdentityState RefreshIdentity()
        {
            bool isCached = true;

            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };
#if BCL || UNITY
                var response = cib.GetId(getIdRequest);
#else
                var response = Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync <GetIdResponse>(() => cib.GetIdAsync(getIdRequest));
#endif
                isCached = false;
                UpdateIdentity(response.IdentityId);
            }
            return(new IdentityState(identityId, isCached));
        }
 /// <summary>
 /// Initiates the asynchronous execution of the GetId operation.
 /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
 /// </summary>
 ///
 /// <param name="request">Container for the necessary parameters to execute the GetId operation on AmazonCognitoIdentityClient.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 ///
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetId
 ///         operation.</returns>
 public IAsyncResult BeginGetId(GetIdRequest request, AsyncCallback callback, object state)
 {
     return(invokeGetId(request, callback, state, false));
 }
        /// <summary>
        /// Generates (or retrieves) a Cognito ID. Supplying multiple logins will create an implicit
        /// linked account.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetId service method.</param>
        ///
        /// <returns>The response from the GetId service method, as returned by CognitoIdentity.</returns>
        /// <exception cref="InternalErrorException">
        /// Thrown when the service encounters an error during processing the request.
        /// </exception>
        /// <exception cref="InvalidParameterException">
        /// Thrown for missing or bad input parameter(s).
        /// </exception>
        /// <exception cref="LimitExceededException">
        /// Thrown when the total number of user pools has exceeded a preset limit.
        /// </exception>
        /// <exception cref="NotAuthorizedException">
        /// Thrown when a user is not authorized to access the requested resource.
        /// </exception>
        /// <exception cref="ResourceConflictException">
        /// Thrown when a user tries to use a login which is already linked to another account.
        /// </exception>
        /// <exception cref="ResourceNotFoundException">
        /// Thrown when the requested resource (for example, a dataset or record) does not exist.
        /// </exception>
        /// <exception cref="TooManyRequestsException">
        /// Thrown when a request is throttled.
        /// </exception>
        public GetIdResponse GetId(GetIdRequest request)
        {
            IAsyncResult asyncResult = invokeGetId(request, null, null, true);

            return(EndGetId(asyncResult));
        }