Пример #1
0
        internal bool VerifyCredentials()
        {
            lock (AuthLock)
            {
                if (AuthToken == null && ImplicitToken == null)
                {
                    Authorize();
                    return(true);
                }
                else
                {
                    if (!RequestedScopes.Contains(Scope.None) || ReauthorizeScopes)
                    {
                        Authorize();
                        return(true);
                    }

                    if (!IsTokenValid())
                    {
                        RefreshAccessToken();
                        return(true);
                    }
                }
                return(true);
            }
        }
Пример #2
0
        /// <summary>Request information about the authorization token.</summary>
        /// <returns>An object containing the returned information, or null if the request failed</returns>
        public TokenVerification VerifyToken()
        {
            while (VerifyCredentials())
            {
                string Token;
                if (AuthToken != null && GrantType == OAuthGrant.Authorization)
                {
                    Token = AuthToken.AccessToken;
                }
                else if (ImplicitToken != null && GrantType == OAuthGrant.Implicit)
                {
                    Token = ImplicitToken.AccessToken;
                }
                else
                {
                    return(null);
                }

                var VerificationClient = new HttpClient();
                VerificationClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
                VerificationClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var Response = VerificationClient.GetAsync("https://login.eveonline.com/oauth/verify").Result;
                if (Response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    return(null);
                }

                var Json   = Response.Content.ReadAsStringAsync().Result;
                var Result = JsonConvert.DeserializeObject <TokenVerification>(Json);
                if (!RequestedScopes.Contains(Scope.None) && !RequestedScopes.TrueForAll(x => Result.Scopes.Contains(x)))
                {
                    ReauthorizeScopes = true;
                }
                else
                {
                    return(Result);
                }
            }
            return(null);
        }