Exemplo n.º 1
0
        public async Task <IResponseResult <BearerToken> > VerifyTokenAsync(BearerToken token)
        {
            var url     = $"{this.AuthApiBaseUrl}/verify-token";
            var headers = HeaderCollection.Add("Authorization", token.ToString());

            return(await this.ExecuteRequestAsync <BearerToken>(HttpMethod.Get, url, null, headers));
        }
Exemplo n.º 2
0
        public async Task <IResponseResult <User> > WhoAmIAsync(BearerToken bearerToken)
        {
            var url     = $"{this.AuthApiBaseUrl}/whoami";
            var headers = HeaderCollection.Add("Authorization", bearerToken.ToString());

            return(await this.ExecuteRequestAsync <User>(HttpMethod.Get, url, null, headers));
        }
Exemplo n.º 3
0
        public IResponseResult RevokeToken(BearerToken token)
        {
            var url     = $"{this.AuthApiBaseUrl}/revoke-token";
            var headers = HeaderCollection.Add("Authorization", token.ToString());

            return(this.ExecuteRequest <BearerToken>(HttpMethod.Get, url, null, headers));
        }
Exemplo n.º 4
0
        public IResponseResult <User> WhoAmI(BearerToken bearerToken)
        {
            var url     = $"{this.BaseUrl}/whoami";
            var headers = HeaderCollection.Add("Authorization", bearerToken.ToString());

            return(this.ExecuteRequest <User>(HttpMethod.Get, url, null, headers));
        }
Exemplo n.º 5
0
        public async Task <IResponseResult> RevokeTokenAsync(BearerToken token, bool logoutFromAllDevices = false)
        {
            var url         = $"{this.BaseUrl}/revoke-token";
            var headers     = HeaderCollection.Add("Authorization", token.ToString());
            var queryString = logoutFromAllDevices ? QueryString.Add("logout-all", true) : QueryString.Empty;

            return(await this.ExecuteRequestAsync(HttpMethod.Get, url, queryString, headers));
        }
Exemplo n.º 6
0
        public async Task <IResponseResult <ITokenValidationResult> > VerifyTokenAsync(BearerToken token)
        {
            var url      = $"{this.BaseUrl}/verify-token";
            var headers  = HeaderCollection.Add("Authorization", token.ToString());
            var response = await this.ExecuteRequestAsync <BearerToken>(HttpMethod.Get, url, null, headers);

            if (response.IsSuccess)
            {
                if (Newtonsoft.Json.JsonConvert.DeserializeObject(response.Json) is JObject jObject)
                {
                    var isVerified     = jObject["verified"]?.Value <bool>();
                    var access_token   = jObject["token"]?.Value <string>();
                    var remaining_time = jObject["remaining_time"]?.Value <int>();

                    if (response.StatusCode != null)
                    {
                        return(new ResponseResult <ITokenValidationResult>(response.StatusCode.Value, response.Message)
                        {
                            Data = new BearerTokenValidationResult(isVerified ?? true, access_token, null, TimeSpan.FromSeconds(remaining_time ?? 0)),
                            Json = response.Json,
                            RawData = response.RawData
                        });
                    }
                    else
                    {
                        return(new ResponseResult <ITokenValidationResult>(response.IsSuccess, response.Message)
                        {
                            Data = new BearerTokenValidationResult(isVerified ?? true, access_token, null, TimeSpan.FromSeconds(remaining_time ?? 0)),
                            Json = response.Json,
                            RawData = response.RawData
                        });
                    }
                }
                else
                {
                    return(new ResponseResult <ITokenValidationResult>(false, "Response success but could not deserialized!")
                    {
                        Json = response.Json,
                        RawData = response.RawData
                    });
                }
            }
            else
            {
                if (response.StatusCode != null)
                {
                    return(new ResponseResult <ITokenValidationResult>(response.StatusCode.Value, response.Message)
                    {
                        Json = response.Json,
                        RawData = response.RawData
                    });
                }
                else
                {
                    return(new ResponseResult <ITokenValidationResult>(response.IsSuccess, response.Message)
                    {
                        Json = response.Json,
                        RawData = response.RawData
                    });
                }
            }
        }