Ejemplo n.º 1
0
        protected async Task AuthorizeClient(AuthValues authValues)
        {
            var client = await AuthService.AuthorizeClient(authValues);

            HttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", client.AccessToken);
        }
Ejemplo n.º 2
0
        protected async Task AuthorizeClient(AuthValues authValues)
        {
            var client = await AuthService.AuthorizeClient(authValues);

            HttpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", client.AccessToken);

            HttpClient.DefaultRequestHeaders.Set("x-proxy-global-company-id", authValues.CompanyId);
            HttpClient.DefaultRequestHeaders.Set("x-api-key", authValues.ClientId);
        }
Ejemplo n.º 3
0
        private async Task <ApiResponse <IdentityClient> > GetClientInfo(AuthValues authValues)
        {
            var clientResponse = await AccuRankerAuthenticationUtils.GetAccessToken(authValues);

            if (clientResponse.HasValue)
            {
                clientResponse.Value.ExpiresIn = 3600;
            }

            return(clientResponse);
        }
        public static async Task <ApiResponse <IdentityClient> > GetAccessToken(AuthValues authValues)
        {
            var client        = new HttpClient();
            var requestParams = new Dictionary <string, string>
            {
                { "client_id", authValues.ClientId },
                { "refresh_token", authValues.RefreshToken },
                { "grant_type", "refresh_token" }
            };

            var result = await client.PostFormResponse <IdentityClient>(AccuRankerCodeAuthBaseUrl, requestParams);

            return(result);
        }
        public static string GetAuthenticationUrl(AuthValues authValues)
        {
            var url   = new UriBuilder(AccuRankerAuthBaseUrl);
            var query = HttpUtility.ParseQueryString(url.Query);

            query["response_type"] = "code";
            query["client_id"]     = authValues.ClientId;
            query["redirect_uri"]  = authValues.RedirectUri;
            query["state"]         = authValues.State;
            query["scope"]         = "read";

            url.Query = query.ToString();

            return(url.ToString());
        }
        public static async Task <ApiResponse <IdentityClient> > GetRefreshToken(AuthValues authValues)
        {
            var client = new HttpClient();

            var uriValues = new Dictionary <string, string>
            {
                { "grant_type", "authorization_code" },
                { "code", authValues.Code },
                { "client_id", authValues.ClientId },
                { "redirect_uri", authValues.RedirectUri }
            };

            var result = await client.PostFormResponse <IdentityClient>(AccuRankerCodeAuthBaseUrl, uriValues);

            return(result);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            _mockRepository = new MockRepository(MockBehavior.Loose);

            _mockAdobeAuthorizationService = _mockRepository.Create <AdobeAuthorizationService>(null);
            _mockHttpClient          = _mockRepository.Create <MoqMessageHandler>();
            _mockHttpClient.CallBase = true;

            _authValues = new AuthValues()
            {
                CompanyId = "company"
            };

            _mockAdobeAuthorizationService
            .Setup(e => e.AuthorizeClient(_authValues))
            .ReturnsAsync(new IdentityClient());
        }
        /// <summary>
        /// Authorizes the client with the given <see cref="AuthValues"/>.
        /// </summary>
        /// <param name="authValues">The values to use for authorization.</param>
        public virtual async Task <IdentityClient> AuthorizeClient(AuthValues authValues)
        {
            if (!IsClientLoggedIn(authValues.Jwt))
            {
                authValues.Jwt = JwtCreator.CreateJwt(authValues);

                var clientInfo = await GetClientInfo(authValues);

                if (clientInfo.Error != null)
                {
                    throw new ApiException(clientInfo.Error);
                }

                if (clientInfo.HasValue)
                {
                    _adobeClientStore.Client = clientInfo.Value;
                }
            }


            return(_adobeClientStore.Client);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Authorizes the client with the given <see cref="AuthValues"/>.
        /// </summary>
        /// <param name="authValues">The values to use for authorization.</param>
        public virtual async Task <IdentityClient> AuthorizeClient(AuthValues authValues)
        {
            if (!IsClientLoggedIn(authValues.RefreshToken))
            {
                var clientInfo = await GetClientInfo(authValues);

                if (clientInfo.HasValue)
                {
                    _clientStore.Client = new IdentityClient
                    {
                        AccessToken  = clientInfo.Value.AccessToken,
                        ExpiresIn    = clientInfo.Value.ExpiresIn,
                        TokenType    = clientInfo.Value.TokenType,
                        RefreshToken = clientInfo.Value.RefreshToken,
                        Scope        = clientInfo.Value.Scope
                    }
                }
                ;
            }


            return(_clientStore.Client);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Sets the auth values for the service to use.
 /// </summary>
 /// <param name="authValues">The auth values.</param>
 public void SetAuthValues(AuthValues authValues)
 {
     AuthValues = authValues;
 }
        private async Task <ApiResponse <IdentityClient> > GetClientInfo(AuthValues authValues)
        {
            var clientResponse = await AdobeAuthenticationUtils.GetAccessToken(authValues);

            return(clientResponse);
        }