public object Get(OAuthAccessTokenRequest request) { // keep this line to inspect the Request in monodevelop's debugger // really helps debugging API calls var servicestack_http_request = this.Request; // TODO the OAuth spec allows other ways of specifying the parameters besides the query string // (i.e. the authorization header, form-encoded POST values, etc. We have to handle those // in the future var original_request = ((HttpListenerRequest)Request.OriginalRequest).ToWebRequest (); try { var context = new OAuthContextBuilder () .FromWebRequest (original_request, new MemoryStream ()); AccessToken access_token = (AccessToken) RainyStandaloneServer.OAuth.Provider.ExchangeRequestTokenForAccessToken (context); Logger.DebugFormat ("permanently authorizing access token: {0}", access_token); RainyStandaloneServer.OAuth.AccessTokens.SaveToken (access_token); Response.Write (access_token.ToString ()); Response.End (); } catch (Exception e) { throw new UnauthorizedException (){ ErrorMessage = "failed to exchange request token for access token: {0}".Fmt(e.Message)}; } return null; }
public object Get(OAuthAccessTokenRequest request) { // keep this line to inspect the Request in monodevelop's debugger // really helps debugging API calls var servicestack_http_request = this.Request; // TODO the OAuth spec allows other ways of specifying the parameters besides the query string // (i.e. the authorization header, form-encoded POST values, etc. We have to handle those // in the future var original_request = ((HttpListenerRequest)Request.OriginalRequest).ToWebRequest(); try { var context = new OAuthContextBuilder() .FromWebRequest(original_request, new MemoryStream()); AccessToken access_token = (AccessToken)RainyStandaloneServer.OAuth.Provider.ExchangeRequestTokenForAccessToken(context); Logger.DebugFormat("permanently authorizing access token: {0}", access_token); RainyStandaloneServer.OAuth.AccessTokens.SaveToken(access_token); Response.Write(access_token.ToString()); Response.End(); } catch (Exception e) { throw new UnauthorizedException() { ErrorMessage = "failed to exchange request token for access token: {0}".Fmt(e.Message) }; } return(null); }
/// <summary> /// Gets an OAuth access token /// </summary> /// <param name="clientId">The client ID</param> /// <param name="clientSecret">The client secret</param> /// <param name="redirectUri">The uri to redirect the results to</param> /// <param name="authorizationCode">The authorization code</param> /// <returns>The OAuth access token</returns> public async Task <OAuthAccessToken> GetAccessTokenAsync(string clientId, string clientSecret, string redirectUri, string authorizationCode) { var url = ConnectClient.UrlProvider.GetOAuthTokenUrl(); var content = new OAuthAccessTokenRequest( clientId, clientSecret, redirectUri, authorizationCode, "authorization_code"); return((await PostJsonAsync <OAuthAccessToken>(url, content, includeCredentials: false)).Payload); }
/// <summary> /// Makes a request to get an access token using the code returned when pipedrive.com redirects back from the URL /// <see cref="GetPipedriveLoginUrl">Pipedrive login url</see> to the application. /// </summary> /// <remarks> /// If the user accepts your request, Pipedrive redirects back to your site with a temporary code in a code /// parameter as well as the state you provided in the previous step in a state parameter. If the states don’t /// match, the request has been created by a third party and the process should be aborted. Exchange this for /// an access token using this method. /// </remarks> /// <param name="request"></param> /// <returns></returns> public async Task <OAuthToken> CreateAccessToken(OAuthAccessTokenRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); var endPoint = ApiUrls.OAuthAccessToken(); var parameters = request.ToParametersDictionary(); parameters.TryGetValue("client_id", out var clientId); parameters.TryGetValue("client_secret", out var clientSecret); var body = new FormUrlEncodedContent(parameters); connection.Credentials = new Credentials(clientId, clientSecret, AuthenticationType.Basic); var response = await connection.Post <OAuthToken>(endPoint, body, "application/json", null, hostAddress).ConfigureAwait(false); return(response.Body); }