public async Task GetAuth() { string state = Request.QueryString["state"]; SpotifyAuthServer <AuthorizationCodeResponse> auth = TokenSwapAuth.GetByState(state); string code = null; string error = Request.QueryString["error"]; if (error == null) { code = Request.QueryString["code"]; } AuthorizationCodeResponse authcode = new AuthorizationCodeResponse { Code = code, Error = error }; TokenSwapAuth au = (TokenSwapAuth)auth; auth?.TriggerAuth(await au.ExchangeCodeAsync(authcode.Code)); await HttpContext.SendStandardHtmlAsync(200, (tw) => { tw.WriteLine(au.HtmlResponse); tw.Flush(); }); }
public Task GetEmpty() { string state = Request.QueryString["state"]; AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer <AuthorizationCodeResponse> auth); string code = null; string error = Request.QueryString["error"]; if (error == null) { code = Request.QueryString["code"]; } AuthorizationCodeResponse authcode = new AuthorizationCodeResponse { Code = code, Error = error }; AuthorizationCodeAuth au = (AuthorizationCodeAuth)auth; Task.Factory.StartNew(async() => auth?.TriggerAuth(await au.ExchangeCode(authcode.Code))); return(HttpContext.SendStandardHtmlAsync(200, (tw) => { tw.WriteLine("<script>window.close()</script>"); tw.Flush(); })); }
public RPAuthenticationConclusion SVX_SignInRP( AuthorizationCodeResponse authorizationCodeResponse, ValidationResponse validationResponse) { return(new RPAuthenticationConclusion { authenticatedClient = authorizationCodeResponse.SVX_sender, googleUsername = validationResponse.googleUsername }); }
private static async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeResponse response) { await _server.Stop(); AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken( new AuthorizationCodeTokenRequest(clientId !, clientSecret !, response.Code, _server.BaseUri) ); await File.WriteAllTextAsync(CredentialsPath, JsonConvert.SerializeObject(token)); await Start(); }
private async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeResponse response) { await StopAndDisposeServer(); var client = new OAuthClient(); var tokenResponse = await client.RequestToken(new PKCETokenRequest(SpotifyOptions.Value.ClientId, response.Code, new Uri(RedirectUri), Verifier)); var authenticator = new PKCEAuthenticator(SpotifyOptions.Value.ClientId, tokenResponse); var config = SpotifyClientConfig.CreateDefault().WithAuthenticator(authenticator); var spotifyClient = new SpotifyClient(config); RunSongExtractor(spotifyClient); }
private async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeResponse response) { await this.server.Stop(); this.server.AuthorizationCodeReceived -= this.OnAuthorizationCodeReceived; AuthorizationCodeTokenResponse tokenResponse = await new OAuthClient().RequestToken( new AuthorizationCodeTokenRequest(this.clientId, this.clientSecret, response.Code, this.server.BaseUri) ); File.WriteAllText(Constants.CredentialsFileName, JsonConvert.SerializeObject(tokenResponse)); this.IsAuthorizationFinished = true; }
public ValidationRequest SVX_MakeValidationRequest(AuthorizationCodeResponse resp) { // May as well fail fast. It should also pass verification to do this in SVX_SignInRP. // Pull new { ... } out to work around BCT mistranslation. var stateParams = new StateParams { client = resp.SVX_sender, idpPrincipal = googlePrincipal }; stateGenerator.Verify(stateParams, resp.state); return(new ValidationRequest { authorizationCode = resp.authorizationCode, rpPrincipal = SVX_Principal // Like in the original authorization code request. }); }
public static AuthorizationCodeResponse Map(AuthorizationCodeResponseViewModel source) { if (source == null) { return(null); } var destination = new AuthorizationCodeResponse { Code = source.Code, State = source.State }; return(destination); }
private static async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeResponse response) { await _server.Stop(); AuthorizationCodeTokenResponse token = await new OAuthClient().RequestToken( new AuthorizationCodeTokenRequest(clientId, clientSecret, response.Code, _server.BaseUri) ); var config = SpotifyClientConfig.CreateDefault().WithToken(token.AccessToken, token.TokenType); var spotify = new SpotifyClient(config); var me = await spotify.UserProfile.Current(); Console.WriteLine($"Your E-Mail: {me.Email}"); Environment.Exit(0); }
public async Task <IOAuthClientResponse> RunFlow( OAuthClientConfiguration oAuthClientConfiguration, AuthorizationCodeResponse authorizationCodeResponse = null, ImplicitFlowResponse implicitFlowResponse = null, DeviceCodeResponse deviceCodeResponse = null, string originalState = null, string codeVerifier = null) { return(oAuthClientConfiguration.FlowType switch { FlowTypes.AuthorizationCode => await RunAuthorizationCodeFlow(authorizationCodeResponse, originalState), FlowTypes.AuthorizationCodeWithPKCE => await RunAuthorizationCodeWithPkceFlow(authorizationCodeResponse, originalState, codeVerifier), FlowTypes.Implicit => RunImplicitFlow(implicitFlowResponse, originalState), FlowTypes.Device => await RunDeviceFlow(deviceCodeResponse), _ => null });
private static async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeResponse response) { var oauth = new OAuthClient(); var tokenRequest = new TokenSwapTokenRequest(new Uri("http://localhost:5001/swap"), response.Code); var tokenResponse = await oauth.RequestToken(tokenRequest); Console.WriteLine($"We got an access token from server: {tokenResponse.AccessToken}"); var refreshRequest = new TokenSwapRefreshRequest( new Uri("http://localhost:5001/refresh"), tokenResponse.RefreshToken ); var refreshResponse = await oauth.RequestToken(refreshRequest); Console.WriteLine($"We got a new refreshed access token from server: {refreshResponse.AccessToken}"); }
private async Task OnAuthCodeRecieved(object sender, AuthorizationCodeResponse response, string verifier) { // Check response and & is valid if (response != null && !string.IsNullOrEmpty(response.Code)) { await _server.Stop(); _pkceToken = await new OAuthClient().RequestToken( new PKCETokenRequest(_clientID, response.Code, _server.BaseUri, verifier) ); // Save PKCE token first SavePKCEToken(_pkceToken); Debug.Log("PKCE: Recieved Auth Code"); SetAuthenticator(_pkceToken); } }
public async Task <IOAuthClientResponse> ExchangeAuthorizationCodeToAccessToken(AuthorizationCodeResponse authorizationCodeResponse) { var requestParams = new Dictionary <string, string> { { Common.GrantType, GrantTypes.AuthorizationCode }, { Common.ClientId, _configuration.ClientId }, { Common.ClientSecret, _configuration.ClientSecret }, { Common.RedirectUri, _configuration.RedirectUri }, { Common.Code, authorizationCodeResponse.Code } }; var requestMessage = new HttpRequestMessage(HttpMethod.Post, _configuration.TokenEndpoint) { Content = new FormUrlEncodedContent(requestParams) }; return(await RunPostRequestAndReturnResult <AccessTokenResponse>(requestMessage)); }
private async Task OnAuthorizationCodeReceivedAsync(object sender, AuthorizationCodeResponse response) { await Server.Stop(); Server.Dispose(); var config = SpotifyClientConfig.CreateDefault(); var tokenResponse = await new OAuthClient(config).RequestToken(new AuthorizationCodeTokenRequest(CLIENT_ID, CLIENT_SECRET, response.Code, new Uri("http://localhost:5000/callback"))); SClient = new SpotifyClient(tokenResponse.AccessToken); SToken = tokenResponse.AccessToken; SRefresh = tokenResponse.RefreshToken; SReady = true; SExpiry = DateTime.Now.AddSeconds(tokenResponse.ExpiresIn); Console.Clear(); await Util.LoggerAsync(new LogMessage(LogSeverity.Info, "Spotify", "Spotify Connected. You can now start queueing songs.")); }