/// <inheritdoc/> public async Task <LoginResult> LoginViaOAuth( HostAddress hostAddress, IGitHubClient client, IOauthClient oauthClient, Action <Uri> openBrowser, CancellationToken cancel) { Guard.ArgumentNotNull(hostAddress, nameof(hostAddress)); Guard.ArgumentNotNull(client, nameof(client)); Guard.ArgumentNotNull(oauthClient, nameof(oauthClient)); Guard.ArgumentNotNull(openBrowser, nameof(openBrowser)); var state = Guid.NewGuid().ToString(); var loginUrl = GetLoginUrl(oauthClient, state); var listen = oauthListener.Listen(state, cancel); openBrowser(loginUrl); var code = await listen.ConfigureAwait(false); var request = new OauthTokenRequest(clientId, clientSecret, code); var token = await oauthClient.CreateAccessToken(request).ConfigureAwait(false); await keychain.Save("[oauth]", token.AccessToken, hostAddress).ConfigureAwait(false); var result = await ReadUserWithRetry(client).ConfigureAwait(false); await keychain.Save(result.User.Login, token.AccessToken, hostAddress).ConfigureAwait(false); return(result); }
/// <summary> /// /// </summary> /// <param name="next"></param> /// <param name="logger"></param> /// <param name="oauthClient"></param> /// <param name="oauthCache"></param> public AuthenticateHandler(RequestDelegate next, ILogger logger, IOauthClient oauthClient, IOauthCache oauthCache) { _next = next; _logger = logger; _oauthClient = oauthClient; _oauthCache = oauthCache; }
public Task <User> LoginViaOAuth( HostAddress hostAddress, IGitHubClient client, IOauthClient oauthClient, Action <Uri> openBrowser, CancellationToken cancel) { return(inner.LoginViaOAuth(hostAddress, client, oauthClient, openBrowser, cancel)); }
Uri GetLoginUrl(IOauthClient client, string state) { var request = new OauthLoginRequest(ApiClientConfiguration.ClientId); request.State = state; foreach (var scope in requestedScopes) { request.Scopes.Add(scope); } var uri = client.GetGitHubLoginUrl(request); // OauthClient.GetGitHubLoginUrl seems to give the wrong URL. Fix this. return(new Uri(uri.ToString().Replace("/api/v3", ""))); }
public CustomAuthenticationAttribute() { _ouathClient = new OauthClient(); _ouathCache = new OAuthCache(); }
public HomeController() { _ouathClient = new OauthClient(); }