/// <summary>
        /// Per the Auth0 documentation at https://auth0.com/docs/tokens/refresh-token/current#get-a-refresh-token
        /// Access Tokens have an expiry, by which time we must exchange the Refresh Code for an updated Access Token to
        /// continue to access the Uluru Cloud Services API.
        /// </summary>
        /// <param name="refreshToken">The refresh token associated with an authorized session - this is used to request a new access token</param>
        /// <returns>An updated set of credentials with refreshed tokens</returns>
        /// <remarks>Make sure the proxy instance that calls this method always has the latest credentials.</remarks>
        public async Task <Credentials> RefreshAccessToken()
        {
            IRestClient client = myRestClientFactory.Create(MyUrlContent.auth0.loginDomainUrl.ToString());

            var request = new RestRequest("/oauth/token", Method.POST);

            request.AddParameter("grant_type", "refresh_token");
            request.AddParameter("client_id", ClientId);
            request.AddParameter("refresh_token", myCredentials.RefreshToken);

            IRestResponse restResponse = await client.ExecutePostTaskAsync(request);

            if (string.IsNullOrWhiteSpace(restResponse.Content) || restResponse.StatusCode != HttpStatusCode.OK)
            {
                if (restResponse.StatusCode == HttpStatusCode.Forbidden)
                {
                    throw new InvalidRefreshTokenException();
                }

                throw new Auth0Exception();
            }

            myCredentials = ExtractTokensFromResponse(restResponse, OAuthGrantType.RefreshToken);

            // Notify subscribers that the credentials have changed.
            CredentialsChanged?.Invoke(this, myCredentials);

            return(myCredentials);
        }
示例#2
0
        void OnCredentialsChanged()
        {
            Credentials.PrivateKey = privateKeyLocationTextEntry.Text ?? string.Empty;
            Credentials.PublicKey  = publicKeyLocationTextEntry.Text ?? string.Empty;
            Credentials.Passphrase = passphraseEntry.Password ?? string.Empty;

            bool privateKeyIsValid = ValidatePrivateKey(Credentials.PrivateKey);
            bool publicKeyIsValid  = System.IO.File.Exists(Credentials.PublicKey);
            bool hasPassphrase     = false;

            if (privateKeyIsValid)
            {
                hasPassphrase = passphraseEntry.Sensitive = GitCredentials.KeyHasPassphrase(Credentials.PrivateKey);
                if (!hasPassphrase)
                {
                    passphraseEntry.Password        = "";
                    passphraseEntry.PlaceholderText = passphraseEntry.Accessible.Description = GettextCatalog.GetString("Private Key is not encrypted");
                }
                warningPrivateKey.Hide();
            }
            else
            {
                warningPrivateKey.Message = GettextCatalog.GetString("Please select a valid private key file");
                warningPrivateKey.Visible = true;
            }

            if (publicKeyIsValid)
            {
                warningPublicKey.Hide();
            }
            else
            {
                warningPublicKey.Message = GettextCatalog.GetString("Please select a valid public key (.pub) file");
                warningPublicKey.Show();
            }

            CredentialsAreValid = privateKeyIsValid && publicKeyIsValid && (!hasPassphrase || Credentials.Passphrase.Length > 0);

            CredentialsChanged?.Invoke(this, EventArgs.Empty);
        }
示例#3
0
 void OnCredentialsChanged()
 {
     Credentials.Username = userTextEntry.Text;
     Credentials.Password = passwordEntry.Password;
     CredentialsChanged?.Invoke(this, EventArgs.Empty);
 }
示例#4
0
 private void OnCredentialsChanged(EventArgs e)
 {
     CredentialsChanged?.Invoke(this, e);
 }