Example #1
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetOpenIdToken operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity.GetOpenIdToken"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken 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 <GetOpenIdTokenResponse> GetOpenIdTokenAsync(GetOpenIdTokenRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetOpenIdTokenRequestMarshaller();
            var unmarshaller = GetOpenIdTokenResponseUnmarshaller.GetInstance();

            return(Invoke <IRequest, GetOpenIdTokenRequest, GetOpenIdTokenResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
Example #2
0
        // Retrieves credentials for the specific role, by making a call to STS
        private CredentialsRefreshState GetCredentialsForRole(string roleArn)
        {
            CredentialsRefreshState credentialsState;
            // Retrieve Open Id Token
            // (Reuses existing IdentityId or creates a new one)
            var getTokenRequest = new GetOpenIdTokenRequest {
                IdentityId = GetIdentityId()
            };

            // If logins are set, pass them to the GetOpenId call
            if (Logins.Count > 0)
            {
                getTokenRequest.Logins = Logins;
            }
            var    getTokenResult = GetOpenId(getTokenRequest);
            string token          = getTokenResult.Token;

            // IdentityId may have changed, save the new value
            UpdateIdentity(getTokenResult.IdentityId, true);

            // Assume role with Open Id Token
            var assumeRequest = new AssumeRoleWithWebIdentityRequest
            {
                WebIdentityToken = token,
                RoleArn          = roleArn,
                RoleSessionName  = "NetProviderSession",
                DurationSeconds  = DefaultDurationSeconds
            };
            var credentials = GetStsCredentials(assumeRequest);

            credentialsState = new CredentialsRefreshState(credentials.GetCredentials(), credentials.Expiration);
            return(credentialsState);
        }
Example #3
0
        /// <summary>
        /// Gets an OpenID token, using a known Cognito ID. This known Cognito ID is returned
        /// from GetId. You can optionally add additional logins for the identity. Supplying multiple
        /// logins creates an implicit link.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken service method.</param>
        ///
        /// <returns>The response from the GetOpenIdToken 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="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 GetOpenIdTokenResponse GetOpenIdToken(GetOpenIdTokenRequest request)
        {
            var marshaller   = new GetOpenIdTokenRequestMarshaller();
            var unmarshaller = GetOpenIdTokenResponseUnmarshaller.Instance;

            return(Invoke <GetOpenIdTokenRequest, GetOpenIdTokenResponse>(request, marshaller, unmarshaller));
        }
Example #4
0
        // This method is to avoid having redundant code based on IsIdentitySet check
        private void GetOpenIdMethod(AmazonServiceResult voidResult, AmazonServiceCallback callback)
        {
            var getTokenRequest = new GetOpenIdTokenRequest
            {
                IdentityId = GetCurrentIdentityId(),
                Logins     = this.Logins
            };

            cib.GetOpenIdTokenAsync(getTokenRequest, delegate(AmazonServiceResult getOpenIdTokenResult)
            {
                if (getOpenIdTokenResult.Exception != null)
                {
                    if (callback != null)
                    {
                        voidResult.Exception = getOpenIdTokenResult.Exception;
                        AmazonMainThreadDispatcher.ExecCallback(callback, voidResult);
                    }
                    return;
                }
                var getOpenIdTokenResponse = getOpenIdTokenResult.Response as GetOpenIdTokenResponse;
                _token = getOpenIdTokenResponse.Token;

                this.UpdateIdentity(getOpenIdTokenResponse.IdentityId);

                AmazonMainThreadDispatcher.ExecCallback(callback, voidResult);
            }, null);
        }
Example #5
0
 private void GetOpenIdWebGL(GetOpenIdTokenRequest getTokenRequest, Action <GetOpenIdTokenResponse, Exception> callback)
 {
     cib.GetOpenIdTokenAsync(getTokenRequest, result =>
     {
         callback(result.Response, result.Exception);
     });
 }
        IAsyncResult invokeGetOpenIdToken(GetOpenIdTokenRequest request, AsyncCallback callback, object state, bool synchronized)
        {
            var marshaller   = new GetOpenIdTokenRequestMarshaller();
            var unmarshaller = GetOpenIdTokenResponseUnmarshaller.Instance;

            return(Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer));
        }
        private async System.Threading.Tasks.Task <CredentialsRefreshState> GetCredentialsForRoleAsync(string roleArn)
        {
            CredentialsRefreshState credentialsState;
            // Retrieve Open Id Token
            // (Reuses existing IdentityId or creates a new one)
            var identity = await GetIdentityIdAsync(RefreshIdentityOptions.Refresh).ConfigureAwait(false);

            var getTokenRequest = new GetOpenIdTokenRequest {
                IdentityId = identity
            };

            // If logins are set, pass them to the GetOpenId call
            if (Logins.Count > 0)
            {
                getTokenRequest.Logins = Logins;
            }

            bool retry = false;
            GetOpenIdTokenResponse getTokenResult = null;

            try
            {
                getTokenResult = await cib.GetOpenIdTokenAsync(getTokenRequest).ConfigureAwait(false);
            }
            catch (AmazonCognitoIdentityException e)
            {
                if (ShouldRetry(e))
                {
                    retry = true;
                }
                else
                {
                    throw;
                }
            }

            if (retry)
            {
                return(await GetCredentialsForRoleAsync(roleArn).ConfigureAwait(false));
            }

            string token = getTokenResult.Token;

            // IdentityId may have changed, save the new value
            UpdateIdentity(getTokenResult.IdentityId);

            // Assume role with Open Id Token
            var assumeRequest = new AssumeRoleWithWebIdentityRequest
            {
                WebIdentityToken = token,
                RoleArn          = roleArn,
                RoleSessionName  = "NetProviderSession",
                DurationSeconds  = DefaultDurationSeconds
            };
            var credentials = (await sts.AssumeRoleWithWebIdentityAsync(assumeRequest).ConfigureAwait(false)).Credentials;

            // Return new refresh state (credentials and expiration)
            credentialsState = new CredentialsRefreshState(credentials.GetCredentials(), credentials.Expiration);
            return(credentialsState);
        }
Example #8
0
        internal GetOpenIdTokenResponse GetOpenIdToken(GetOpenIdTokenRequest request)
        {
            GetOpenIdTokenRequestMarshaller    marshaller = new GetOpenIdTokenRequestMarshaller();
            GetOpenIdTokenResponseUnmarshaller instance   = GetOpenIdTokenResponseUnmarshaller.Instance;

            return(Invoke <GetOpenIdTokenRequest, GetOpenIdTokenResponse>(request, marshaller, instance));
        }
Example #9
0
        public void GetOpenIdTokenAsync(string identityId, AmazonServiceCallback <GetOpenIdTokenRequest, GetOpenIdTokenResponse> callback, AsyncOptions options = null)
        {
            GetOpenIdTokenRequest getOpenIdTokenRequest = new GetOpenIdTokenRequest();

            getOpenIdTokenRequest.IdentityId = identityId;
            GetOpenIdTokenAsync(getOpenIdTokenRequest, callback, options);
        }
Example #10
0
        private void GetCredentialsForRoleWebGL(string roleArn, Action <CredentialsRefreshState> callback)
        {
            CredentialsRefreshState credentialsState;

            // Retrieve Open Id Token
            // (Reuses existing IdentityId or creates a new one)
            this.GetIdentityIdWebGL(RefreshIdentityOptions.Refresh, identity =>
            {
                var getTokenRequest = new GetOpenIdTokenRequest {
                    IdentityId = identity
                };
                // If logins are set, pass them to the GetOpenId call
                if (Logins.Count > 0)
                {
                    getTokenRequest.Logins = Logins;
                }

                GetOpenIdWebGL(getTokenRequest, (getTokenResult, e) =>
                {
                    bool retry = false;

                    if (e is AmazonCognitoIdentityException)
                    {
                        if (ShouldRetry(e as AmazonCognitoIdentityException))
                        {
                            retry = true;
                        }
                        else
                        {
                            throw e;
                        }
                    }

                    if (retry)
                    {
                        GetCredentialsForRoleWebGL(roleArn, callback);
                        return;
                    }

                    string token = getTokenResult.Token;

                    // IdentityId may have changed, save the new value
                    UpdateIdentity(getTokenResult.IdentityId);

                    // Assume role with Open Id Token
                    var assumeRequest = new AssumeRoleWithWebIdentityRequest
                    {
                        WebIdentityToken = token,
                        RoleArn          = roleArn,
                        RoleSessionName  = "NetProviderSession",
                        DurationSeconds  = DefaultDurationSeconds
                    };
                    var credentials = GetStsCredentials(assumeRequest);

                    credentialsState = new CredentialsRefreshState(credentials.GetCredentials(), credentials.Expiration);
                    callback(credentialsState);
                });
            });
        }
Example #11
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetOpenIdToken operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken 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 EndGetOpenIdToken
        ///         operation.</returns>
        public IAsyncResult BeginGetOpenIdToken(GetOpenIdTokenRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new GetOpenIdTokenRequestMarshaller();
            var unmarshaller = GetOpenIdTokenResponseUnmarshaller.Instance;

            return(BeginInvoke <GetOpenIdTokenRequest>(request, marshaller, unmarshaller,
                                                       callback, state));
        }
Example #12
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetOpenIdToken operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken 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 <GetOpenIdTokenResponse> GetOpenIdTokenAsync(GetOpenIdTokenRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetOpenIdTokenRequestMarshaller();
            var unmarshaller = GetOpenIdTokenResponseUnmarshaller.Instance;

            return(InvokeAsync <GetOpenIdTokenRequest, GetOpenIdTokenResponse>(request, marshaller,
                                                                               unmarshaller, cancellationToken));
        }
        // Retrieves credentials for the specific role, by making a call to STS
        private CredentialsRefreshState GetCredentialsForRole(string roleArn)
        {
            CredentialsRefreshState credentialsState;
            // Retrieve Open Id Token
            // (Reuses existing IdentityId or creates a new one)
            var identity        = this.GetIdentityId(RefreshIdentityOptions.Refresh);
            var getTokenRequest = new GetOpenIdTokenRequest {
                IdentityId = identity
            };

            // If logins are set, pass them to the GetOpenId call
            if (Logins.Count > 0)
            {
                getTokenRequest.Logins = Logins;
            }

            bool retry = false;
            GetOpenIdTokenResponse getTokenResult = null;

            try
            {
                getTokenResult = GetOpenId(getTokenRequest);
            }
            catch (AmazonCognitoIdentityException e)
            {
                if (ShouldRetry(e))
                {
                    retry = true;
                }
                else
                {
                    throw;
                }
            }

            if (retry)
            {
                return(GetCredentialsForRole(roleArn));
            }

            string token = getTokenResult.Token;

            // IdentityId may have changed, save the new value
            UpdateIdentity(getTokenResult.IdentityId);

            // Assume role with Open Id Token
            var assumeRequest = new AssumeRoleWithWebIdentityRequest
            {
                WebIdentityToken = token,
                RoleArn          = roleArn,
                RoleSessionName  = "NetProviderSession",
                DurationSeconds  = DefaultDurationSeconds
            };
            var credentials = GetStsCredentials(assumeRequest);

            credentialsState = new CredentialsRefreshState(credentials.GetCredentials(), credentials.Expiration);
            return(credentialsState);
        }
Example #14
0
        /// <summary>
        /// Gets an OpenID token, using a known Cognito ID. This known Cognito ID is returned
        /// from GetId. You can optionally add additional logins for the identity. Supplying multiple
        /// logins creates an implicit link.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken service method.</param>
        ///
        /// <returns>The response from the GetOpenIdToken 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.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 GetOpenIdTokenResponse GetOpenIdToken(GetOpenIdTokenRequest request)
        {
            var task = GetOpenIdTokenAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the GetOpenIdToken operation.
        /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken 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 GetOpenIdTokenAsync(GetOpenIdTokenRequest 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 GetOpenIdTokenRequestMarshaller();
                var unmarshaller = GetOpenIdTokenResponseUnmarshaller.Instance;
                Invoke(request, callback, state, marshaller, unmarshaller, signer);
            }));
            return;
        }
Example #16
0
        public void GetOpenIdTokenAsync(GetOpenIdTokenRequest request, AmazonServiceCallback <GetOpenIdTokenRequest, GetOpenIdTokenResponse> callback, AsyncOptions options = null)
        {
            options = ((options == null) ? new AsyncOptions() : options);
            GetOpenIdTokenRequestMarshaller    marshaller = new GetOpenIdTokenRequestMarshaller();
            GetOpenIdTokenResponseUnmarshaller instance   = GetOpenIdTokenResponseUnmarshaller.Instance;
            Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;

            if (callback != null)
            {
                callbackHelper = delegate(AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao)
                {
                    AmazonServiceResult <GetOpenIdTokenRequest, GetOpenIdTokenResponse> responseObject = new AmazonServiceResult <GetOpenIdTokenRequest, GetOpenIdTokenResponse>((GetOpenIdTokenRequest)req, (GetOpenIdTokenResponse)res, ex, ao.State);
                    callback(responseObject);
                };
            }
            BeginInvoke(request, marshaller, instance, options, callbackHelper);
        }
        private CredentialsRefreshState GetCredentialsForRole(string roleArn)
        {
            string text = GetIdentityId(RefreshIdentityOptions.Refresh);
            GetOpenIdTokenRequest getOpenIdTokenRequest = new GetOpenIdTokenRequest
            {
                IdentityId = text
            };

            if (Logins.Count > 0)
            {
                getOpenIdTokenRequest.Logins = Logins;
            }
            bool flag = false;
            GetOpenIdTokenResponse getOpenIdTokenResponse = null;

            try
            {
                getOpenIdTokenResponse = GetOpenId(getOpenIdTokenRequest);
            }
            catch (AmazonCognitoIdentityException e)
            {
                if (!ShouldRetry(e))
                {
                    throw;
                }
                flag = true;
            }
            if (flag)
            {
                return(GetCredentialsForRole(roleArn));
            }
            string token = getOpenIdTokenResponse.Token;

            UpdateIdentity(getOpenIdTokenResponse.IdentityId);
            AssumeRoleWithWebIdentityRequest assumeRequest = new AssumeRoleWithWebIdentityRequest
            {
                WebIdentityToken = token,
                RoleArn          = roleArn,
                RoleSessionName  = "NetProviderSession",
                DurationSeconds  = DefaultDurationSeconds
            };

            Amazon.SecurityToken.Model.Credentials stsCredentials = GetStsCredentials(assumeRequest);
            return(new CredentialsRefreshState(stsCredentials.GetCredentials(), stsCredentials.Expiration));
        }
Example #18
0
        private async System.Threading.Tasks.Task <CredentialsRefreshState> GetCredentialsForRoleAsync(string roleArn)
        {
            CredentialsRefreshState credentialsState;
            // Retrieve Open Id Token
            // (Reuses existing IdentityId or creates a new one)
            var identityId = await GetIdentityIdAsync().ConfigureAwait(false);

            var getTokenRequest = new GetOpenIdTokenRequest {
                IdentityId = identityId
            };

            // If logins are set, pass them to the GetOpenId call
            if (Logins.Count > 0)
            {
                getTokenRequest.Logins = Logins;
            }
            var getTokenResult = await cib.GetOpenIdTokenAsync(getTokenRequest).ConfigureAwait(false);

            string token = getTokenResult.Token;

            // IdentityId may have changed, save the new value
            UpdateIdentity(getTokenResult.IdentityId, true);

            // Assume role with Open Id Token
            var assumeRequest = new AssumeRoleWithWebIdentityRequest
            {
                WebIdentityToken = token,
                RoleArn          = roleArn,
                RoleSessionName  = "NetProviderSession",
                DurationSeconds  = DefaultDurationSeconds
            };
            var credentials = (await sts.AssumeRoleWithWebIdentityAsync(assumeRequest).ConfigureAwait(false)).Credentials;

            // Return new refresh state (credentials and expiration)
            credentialsState = new CredentialsRefreshState(credentials.GetCredentials(), credentials.Expiration);
            return(credentialsState);
        }
 /// <summary>
 /// Initiates the asynchronous execution of the GetOpenIdToken operation.
 /// <seealso cref="Amazon.CognitoIdentity.IAmazonCognitoIdentity"/>
 /// </summary>
 ///
 /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken 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 EndGetOpenIdToken
 ///         operation.</returns>
 public IAsyncResult BeginGetOpenIdToken(GetOpenIdTokenRequest request, AsyncCallback callback, object state)
 {
     return(invokeGetOpenIdToken(request, callback, state, false));
 }
        private GetOpenIdTokenResponse GetOpenId(GetOpenIdTokenRequest getTokenRequest)
        {
            var getTokenResult = Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync <GetOpenIdTokenResponse>(() => cib.GetOpenIdTokenAsync(getTokenRequest));

            return(getTokenResult);
        }
Example #21
0
        private GetOpenIdTokenResponse GetOpenId(GetOpenIdTokenRequest getTokenRequest)
        {
            var getTokenResult = cib.GetOpenIdToken(getTokenRequest);

            return(getTokenResult);
        }
 private GetOpenIdTokenResponse GetOpenId(GetOpenIdTokenRequest getTokenRequest)
 {
     return(cib.GetOpenIdToken(getTokenRequest));
 }
        /// <summary>
        /// Gets an OpenID token, using a known Cognito ID. This known Cognito ID is returned
        /// from GetId. You can optionally add additional logins for the identity. Supplying multiple
        /// logins creates an implicit link.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetOpenIdToken service method.</param>
        ///
        /// <returns>The response from the GetOpenIdToken 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="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 GetOpenIdTokenResponse GetOpenIdToken(GetOpenIdTokenRequest request)
        {
            IAsyncResult asyncResult = invokeGetOpenIdToken(request, null, null, true);

            return(EndGetOpenIdToken(asyncResult));
        }