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 }; }