Exemplo n.º 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)
        {
            if (!createFromRefreshTokenParameters.ContainerMap.ContainsKey("client_id"))
            {
                createFromRefreshTokenParameters.ContainerMap["client_id"] = apiContext.Config[BaseConstants.ClientId];
            }
            if (!createFromRefreshTokenParameters.ContainerMap.ContainsKey("client_secret"))
            {
                createFromRefreshTokenParameters.ContainerMap["client_secret"] = apiContext.Config[BaseConstants.ClientSecret];
            }
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&refresh_token={1}&scope={2}&client_id={3}&client_secret={4}";

            createFromRefreshTokenParameters.SetRefreshToken(WebUtility.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(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders   = headersMap;
            apiContext.MaskRequestId = true;

            // Set the authentication header
            byte[] bytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", apiContext.Config[BaseConstants.ClientId], apiContext.Config[BaseConstants.ClientSecret]));
            apiContext.AccessToken = Convert.ToBase64String(bytes);

            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Exemplo n.º 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(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders   = headersMap;
            apiContext.MaskRequestId = true;
            return(PayPalResource.ConfigureAndExecute <Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad));
        }
Exemplo n.º 3
0
        public void UserInfoGetUserInfoWithRefreshTokenTest()
        {
            try
            {
                var config = ConfigManager.Instance.GetProperties();
                config[BaseConstants.ClientId] = "AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS";
                config[BaseConstants.ClientSecret] = "EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL";
                var apiContext = new APIContext() { Config = config };

                // Using the refresh token, first get an access token.
                var tokenInfo = new Tokeninfo();
                tokenInfo.refresh_token = "W1JmxG-Cogm-4aSc5Vlen37XaQTj74aQcQiTtXax5UgY7M_AJ--kLX8xNVk8LtCpmueFfcYlRK6UgQLJ-XHsxpw6kZzPpKKccRQeC4z2ldTMfXdIWajZ6CHuebs";
                var refreshTokenParameters = new CreateFromRefreshTokenParameters();
                var token = tokenInfo.CreateFromRefreshToken(apiContext, refreshTokenParameters);
                this.RecordConnectionDetails();

                var userInfoParameters = new UserinfoParameters();
                userInfoParameters.SetAccessToken(token.access_token);

                // Get the user information.
                var userInfo = PayPal.Api.OpenIdConnect.Userinfo.GetUserinfo(userInfoParameters);
                this.RecordConnectionDetails();

                Assert.AreEqual("account", userInfo.family_name);
                Assert.AreEqual("facilitator account", userInfo.name);
                Assert.AreEqual("facilitator", userInfo.given_name);
                Assert.AreEqual("BUSINESS", userInfo.account_type);
                Assert.AreEqual("https://www.paypal.com/webapps/auth/identity/user/jWZav5QbA94DNm5FzsNOsq88y4QYrRvu4KLfUydcJqU", userInfo.user_id);
                Assert.IsTrue(userInfo.verified_account.Value);
                Assert.AreEqual("en_US", userInfo.locale);
            }
            catch(ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
Exemplo n.º 4
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)
 {
     return(CreateFromRefreshToken(null, createFromRefreshTokenParameters));
 }
Exemplo n.º 5
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)
        {
            if(!createFromRefreshTokenParameters.ContainerMap.ContainsKey("client_id"))
            {
                createFromRefreshTokenParameters.ContainerMap["client_id"] = apiContext.Config[BaseConstants.ClientId];
            }
            if (!createFromRefreshTokenParameters.ContainerMap.ContainsKey("client_secret"))
            {
                createFromRefreshTokenParameters.ContainerMap["client_secret"] = apiContext.Config[BaseConstants.ClientSecret];
            }
            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(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
            if (apiContext == null)
            {
                apiContext = new APIContext();
            }
            apiContext.HTTPHeaders = headersMap;
            apiContext.MaskRequestId = true;

            // Set the authentication header
            byte[] bytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", apiContext.Config[BaseConstants.ClientId], apiContext.Config[BaseConstants.ClientSecret]));
            apiContext.AccessToken = Convert.ToBase64String(bytes);

            return PayPalResource.ConfigureAndExecute<Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad);
        }
Exemplo n.º 6
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)
 {
     return CreateFromRefreshToken(null, createFromRefreshTokenParameters);
 }
Exemplo n.º 7
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(BaseConstants.ContentTypeHeader, "application/x-www-form-urlencoded");
     if (apiContext == null)
     {
         apiContext = new APIContext();
     }
     apiContext.HTTPHeaders = headersMap;
     apiContext.MaskRequestId = true;
     return PayPalResource.ConfigureAndExecute<Tokeninfo>(apiContext, HttpMethod.POST, resourcePath, payLoad);
 }