예제 #1
0
        /// <summary>
        /// Creates an Access Token from an Refresh Token
        /// <param name="apiContext">APIContext to be used for the call</param>
        /// <param name="createFromRefreshTokenParameters">Query parameters used for API call</param>
        /// </summary>
        public Tokeninfo CreateFromRefreshToken(APIContext apiContext, CreateFromRefreshTokenParameters createFromRefreshTokenParameters)
        {
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&refresh_token={1}&scope={2}&client_id={3}&client_secret={4}";

            createFromRefreshTokenParameters.setRefreshToken(HttpUtility.UrlEncode(refresh_token));
            object[] parameters   = new object[] { createFromRefreshTokenParameters };
            string   resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
            string   payLoad      = resourcePath.Substring(resourcePath.IndexOf('?') + 1);

            resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
            Dictionary <string, string> headersMap = new Dictionary <string, string>();

            if (createFromRefreshTokenParameters.getClientId() != null && createFromRefreshTokenParameters.getClientSecret() != null)
            {
                OAuthTokenCredential oauthTokenCredential = new OAuthTokenCredential(createFromRefreshTokenParameters.getClientId(), createFromRefreshTokenParameters.getClientSecret());
                headersMap.Add("Authorization", oauthTokenCredential.GenerateBasicAuthHeader());
            }
            headersMap.Add("Content-Type", "application/x-www-form-urlencoded");
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext,
                                                                  HttpMethod.POST, resourcePath, headersMap, payLoad));
        }
예제 #2
0
 /// <summary>
 /// Creates an Access Token from an Refresh Token
 /// <param name="apiContext">APIContext to be used for the call</param>
 /// <param name="createFromRefreshTokenParameters">Query parameters used for API call</param>
 /// </summary>
 public Tokeninfo CreateFromRefreshToken(APIContext apiContext, CreateFromRefreshTokenParameters createFromRefreshTokenParameters)
 {
     string pattern = "v1/identity/openidconnect/tokenservice ?grant_type={0}&refresh_token={1}&scope={2}&client_id={3}&client_secret={4}";
     createFromRefreshTokenParameters.setRefreshToken(HttpUtility.UrlEncode(refresh_token));
     object[] parameters = new object[] { createFromRefreshTokenParameters };
     string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
     string payLoad = resourcePath.Substring(resourcePath.IndexOf('?') + 1);
     resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
     Dictionary<string, string> headersMap = new Dictionary<string, string>();
     headersMap.Add("Content-Type", "application/x-www-form-urlencoded");
     return PayPalResource.ConfigureAndExecute<Tokeninfo>(apiContext,
         HttpMethod.POST, resourcePath, headersMap, payLoad);
 }
예제 #3
0
 /// <summary>
 /// Creates an Access Token from an Refresh Token.
 /// <param name="createFromRefreshTokenParameters">Query parameters used for API call</param>
 /// </summary>
 public Tokeninfo CreateFromRefreshToken(CreateFromRefreshTokenParameters createFromRefreshTokenParameters)
 {
     string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&refresh_token={1}&scope={2}&client_id={3}&client_secret={4}";
     createFromRefreshTokenParameters.setRefreshToken(HttpUtility.UrlEncode(refresh_token));
     object[] parameters = new object[] { createFromRefreshTokenParameters };
     string resourcePath = SDKUtil.FormatURIPath(pattern, parameters);
     string payLoad = resourcePath.Substring(resourcePath.IndexOf('?') + 1);
     resourcePath = resourcePath.Substring(0, resourcePath.IndexOf("?"));
     Dictionary<string, string> headersMap = new Dictionary<string, string>();
     if (createFromRefreshTokenParameters.getClientId() != null && createFromRefreshTokenParameters.getClientSecret() != null)
     {
     OAuthTokenCredential oauthTokenCredential = new OAuthTokenCredential(createFromRefreshTokenParameters.getClientId(), createFromRefreshTokenParameters.getClientSecret());
     headersMap.Add("Authorization", oauthTokenCredential.GenerateBasicAuthHeader());
     }
     headersMap.Add("Content-Type", "application/x-www-form-urlencoded");
     return PayPalResource.ConfigureAndExecute<Tokeninfo>(null, HttpMethod.POST,
         resourcePath, headersMap, payLoad);
 }