Example #1
0
        public CharacterRolesModel GetCharacterRoles()
        {
            if (CheckScope("esi-characters.read_corporation_roles.v1") == false)
            {
                return(null);
            }

            if (characterRolesResponse != null)
            {
                if (EveHelper.GetCacheTimer(characterRolesResponse) > DateTime.UtcNow)
                {
                    return(characterRoles);
                }
            }

            RestClient  Client  = new RestClient("https://esi.tech.ccp.is");
            RestRequest request = new RestRequest(CharacterRolesModel.EndpointVersioned, Method.GET);

            request.AddUrlSegment("character_id", this.CharacterId);
            characterRolesResponse = Client.Execute <CharacterRolesModel>(request);
            characterRoles         = characterRolesResponse.Data;

            OnTokenUpdated?.Invoke();
            return(characterRoles);
        }
Example #2
0
        /// <summary>
        /// Request a new bearer token and store it on the local Account.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>Returns success state</returns>
        public static async Task <bool> RequestToken(string username, string password)
        {
            var authenticator = new OAuth2PasswordCredentialsAuthenticator(TokenEndpoint);

            authenticator.SetCredentials(username, password);

            try
            {
                var account = await authenticator.SignInAsync();

                if (account == null)
                {
                    return(false);
                }

                account.Properties.Add("password", password);
                account.Properties.Add("date", DateTime.Now.ToString());

                await AccountStore.SaveAsync(account, App.Settings.ServiceId);

                AuthAccount = account;
                OnTokenUpdated?.Invoke(null, (string)account.Properties["access_token"]);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// Update access token if it is expired
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Access token</returns>
        protected async Task UpdateTokenAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_token.ExpireDateTime > DateTime.UtcNow.AddMinutes(-1))
            {
                return;
            }

            var nToken = await _oAuth2Provider.GenerateAccessTokenAsync(_token.RefreshToken, cancellationToken).ConfigureAwait(false);

            _token = new Token(nToken.AccessToken, nToken.TokenType, nToken.ExpiresIn, _token.RefreshToken, nToken.ExpireDateTime);
            OnTokenUpdated?.Invoke(this, _token);
        }
Example #4
0
        /// <summary>
        /// Fully refreshes the token's AccessToken and VerificationInfo fields.
        /// </summary>
        /// <returns></returns>
        public async Task Refresh()
        {
            if (this.RefreshToken == null)
            {
                return;
            }
            DateTime now = DateTime.Now;
            DateTime exp = DateTime.Parse(Expiry);

            if (now < exp)
            {
                return; // Token is not expired, no need to refresh it.
            }
            tokenAccessInfo = await AuthClient.RequestAccessToken(tokenAccessInfo.RefreshToken);

            tokenVerification = await AuthClient.RequestTokenVerificationOld(tokenAccessInfo.AccessToken);

            OnTokenUpdated?.Invoke();
        }
Example #5
0
        public CharacterPublicInformation GetCharacterInformation()
        {
            // If exists AND cache has not expired, return existing entry.
            if (characterInformationResponse != null)
            {
                if (EveHelper.GetCacheTimer(characterInformationResponse) > DateTime.UtcNow)
                {
                    return(characterInformation);
                }
            }

            RestClient  Client  = new RestClient("https://esi.tech.ccp.is");
            RestRequest request = new RestRequest(CharacterPublicInformation.EndpointVersioned, Method.GET);

            request.AddUrlSegment("character_id", this.CharacterId);
            characterInformationResponse = Client.Execute <CharacterPublicInformation>(request);

            characterInformation = characterInformationResponse.Data;

            OnTokenUpdated?.Invoke();
            return(characterInformation);
        }