static void Main(string[] args) { Console.Write("Client ID: "); var clientId = Console.ReadLine(); Console.Write("Client Secret: "); var clientSecret = Console.ReadLine(); Console.WriteLine("Please authenticate to HiDrive in your browser and come back here."); var authenticator = new HiDriveAuthenticator(clientId, clientSecret); var scope = new AuthorizationScope(AuthorizationRole.User, AuthorizationPermission.ReadWrite); var authUrl = authenticator.GetAuthorizationCodeRequestUrl(scope); Process.Start(authUrl); Console.Write("Code: "); var code = Console.ReadLine(); Console.WriteLine("Gathering RefreshToken..."); var token = authenticator.AuthenticateByAuthorizationCodeAsync(code); token.Wait(); Console.WriteLine("RefreshToken: {0}", token.Result.RefreshToken); WriteClientConfiguration(clientId, clientSecret, token.Result.RefreshToken); Console.ReadLine(); }
public async Task<HiDriveAccount> Handle(string authorizationCode) { var hiDriveAuthenticator = new HiDriveAuthenticator(_hiDriveApiOptions.Value.HiDriveClientId, _hiDriveApiOptions.Value.HiDriveClientSecret); var oAuth2Token = await hiDriveAuthenticator.AuthenticateByAuthorizationCodeAsync(authorizationCode); var hiDriveClient = new HiDriveClient.HiDriveClient(hiDriveAuthenticator); var user = await hiDriveClient.User.Me.Get().ExecuteAsync(); return new HiDriveAccount { AccountId = user.Account, UserName = user.Alias, RefreshToken = oAuth2Token.RefreshToken }; }
public async Task AuthenticateByRefreshTokenWithInvalidClientId() { var sut = new HiDriveAuthenticator("invalid_id", ClientConfiguration.ClientSecret); try { var result = await sut.AuthenticateByRefreshTokenAsync(ClientConfiguration.RefreshToken); Assert.Fail("AuthenticationException expected"); } catch (AuthenticationException ex) { var error = ex.Error; Assert.IsNotNull(error); Assert.AreEqual("invalid_request", error.Error); Assert.AreEqual("invalid client_id (param auth)", error.Description); } }
static BaseRequestTest() { Authenticator = new HiDriveAuthenticator(ClientConfiguration.ClientId, ClientConfiguration.ClientSecret); Authenticator.AuthenticateByRefreshTokenAsync(ClientConfiguration.RefreshToken).Wait(); }
public async Task Handle(string refreshToken) { var hiDriveAuthenticator = new HiDriveAuthenticator(_hiDriveApiOptions.Value.HiDriveClientId, _hiDriveApiOptions.Value.HiDriveClientSecret); await hiDriveAuthenticator.RevokeRefreshToken(refreshToken); }