Exemplo n.º 1
0
        /// <summary>
        /// Method that request an Application User Token for Spei Operations
        /// </summary>
        /// <param name="request">Object that includes all information for the token</param>
        /// <returns>return the token data </returns>
        public string GetApplicationUserToken(TokenRequest request)
        {
            string      keySearch   = request.UserKey + ScopeType.SpeiAdmin.ScopeName;
            CachedToken cachedToken = GetCachedToken(keySearch);

            string bearer;

            if (cachedToken != null)
            {
                bearer = FormatToHeader(cachedToken.GetToken().AccessToken);
            }
            else
            {
                TokenResponse tokenResponse = GetToken(request.ClientKey, request.ClientSecret, string.Format(
                                                           USER_TOKEN_TEMPLATE, GrantType.Password.GrantTypeName, ScopeType.SpeiAdmin.ScopeName, request.UserKey, request.UserSecret));

                this.tokensCached.Add(keySearch, new CachedToken(request.UserKey, request.UserSecret, tokenResponse));
                bearer = FormatToHeader(tokenResponse.AccessToken);
            }

            return(bearer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method that request an Application Token
        /// </summary>
        /// <param name="request">Object that includes all information for the token</param>
        /// <returns>return the token data </returns>
        public string GetApplicationToken(TokenRequest request)
        {
            string      keySearch   = request.ClientKey + ScopeType.General.ScopeName;
            CachedToken cachedToken = GetCachedToken(keySearch);

            string bearer;

            if (cachedToken != null)
            {
                bearer = FormatToHeader(cachedToken.GetToken().AccessToken);
            }
            else
            {
                TokenResponse tokenResponse = GetToken(request.ClientKey, request.ClientSecret, string.Format(
                                                           APPLICATION_TOKEN_TEMPLATE, GrantType.ClientCredentials.GrantTypeName, ScopeType.General.ScopeName));

                this.tokensCached.Add(keySearch, new CachedToken(null, null, tokenResponse));
                bearer = FormatToHeader(tokenResponse.AccessToken);
            }

            return(bearer);
        }