Example #1
0
        /// <summary>
        /// Envía al servicio la solicitud de generación de un token de autenticación.
        /// </summary>
        /// <returns>Instancia de <see cref="ISession{TFluent}" /> que permite el acceso a las operaciones del servicio.</returns>
        public ISession <IAutonomousApp> Authenticate()
        {
            this.AuthToken = CacheStore.GetCurrentAuthToken(this.AppIdentity.ApiKey);
            if (this.AuthToken != null)
            {
                return(this);
            }

            this.InitializeClient();
            IRestRequest request = new AspenRequest(Scope.Autonomous, EndpointMapping.Signin);

            ServiceLocator.Instance.HeadersManager.AddApiKeyHeader(request, this.AppIdentity.ApiKey);
            ServiceLocator.Instance.HeadersManager.AddSigninPayloadHeader(request, this.JwtEncoder, this.AppIdentity.ApiSecret);
            ServiceLocator.Instance.HeadersManager.AddApiVersionHeader(request, null);
            IRestResponse response = base.Execute(request);

            this.AuthToken = JsonConvert.DeserializeObject <AuthToken>(this.DecodeJwtResponse(response.Content));
            CacheStore.SetCurrentAuthToken(this.AppIdentity.ApiKey, this.AuthToken);
            return(this);
        }