void HandleTokenAcquisition(bool wasAcquiredSilently) { UserInfo = appAuthService.GetUserInfo(AuthenticationResult.IdToken); OnAuthChanged?.Invoke(this, new AuthChangedEventArgs { IsLoggedIn = AuthenticationResult != null, WasTokenAcquiredSilently = wasAcquiredSilently, }); }
public static OAuthResponse ExchangeCode(string code) { if (!String.IsNullOrEmpty(code) && response == null) { try { using (var web = new HttpClient()) { var response = web.PostAsync($"https://github.com/login/oauth/access_token", new StringContent(Stringfy(new GitHubOAuthRequest() { client_id = client_id, client_secret = secret, redirect_uri = redirect_uri, code = GetCode(code) }), System.Text.Encoding.UTF8, "application/json")).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; GitHubOAuthHelpers.response = ParseCodeResponse(content); OnAuthChanged?.Invoke(true); return(ParseCodeResponse(content)); } throw new Exception("Bad Request"); } } catch (Exception ex) { OnAuthChanged?.Invoke(false); return(null); } } else { OnAuthChanged?.Invoke(false); return(null); } }