Пример #1
0
        public void testGetAuthUrl()
        {
            Dictionary<String, String> configurationMap = new Dictionary<string, string>();
            string clientId = "AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd";
            string clientSecret = "EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX";
            configurationMap.Add("mode", "sandbox");

            APIContext apiContext = new APIContext();
            apiContext.Config = configurationMap;
            List<string> scopelist = new List<string>();
            scopelist.Add("openid");
            scopelist.Add("email");
            string redirectURI = "https://devtools-paypal.com";
            string redirectURL = Session.GetRedirectURL(clientId, redirectURI, scopelist, apiContext);
            Console.WriteLine(redirectURL);
            CreateFromAuthorizationCodeParameters param = new CreateFromAuthorizationCodeParameters();

            param.setClientId(clientId);
            param.setClientSecret(clientSecret);
            // code you will get back as part of the url after redirection
            param.setCode("VxirnJHENB8k5slnoqZOdmjQcCMJRvbI-ispixwWHke-gsOh6XJaWQNJuTCTp3n3o6ttQs3VoNX1De3HOVpmH2PLN53PPedZcTujzLqYrlTS-CqKHYb5wb0NT2joumArOdEy51D4HgoCa46dxuPMm79nX40RQXRP8J0OQsgrEbhf_Kna");
            Tokeninfo info = Tokeninfo.CreateFromAuthorizationCode(apiContext, param);
            UserinfoParameters userinfoParams = new UserinfoParameters();
            userinfoParams.setAccessToken(info.access_token);
            Userinfo userinfo = Userinfo.GetUserinfo(apiContext, userinfoParams);

            Console.WriteLine("Email" + userinfo.email);
        }
Пример #2
0
        /// <summary>
        /// Creates an Access Token from an Authorization Code.
        /// <param name="apiContext">APIContext to be used for the call.</param>
        /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
        /// </summary>
        public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
        {
            string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";

            object[] parameters   = new object[] { createFromAuthorizationCodeParameters };
            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 (createFromAuthorizationCodeParameters.getClientId() != null && createFromAuthorizationCodeParameters.getClientSecret() != null)
            {
                OAuthTokenCredential oauthTokenCredential = new OAuthTokenCredential(createFromAuthorizationCodeParameters.getClientId(), createFromAuthorizationCodeParameters.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));
        }
Пример #3
0
        public void testGetAuthUrl()
        {
            Dictionary<String, String> configurationMap = new Dictionary<string, string>();
            configurationMap.Add("ClientID", "dummy");
            configurationMap.Add("ClientSecret",
                    "dummypassword");
            configurationMap.Add("mode", "live");
            APIContext apiContext = new APIContext();
            apiContext.Config = configurationMap;
            List<string> scopelist = new List<string>();
            scopelist.Add("openid");
            scopelist.Add("email");
            string redirectURI = "http://google.com";
               string redirectURL = Session.GetRedirectURL(redirectURI,scopelist,apiContext);
               Console.WriteLine(redirectURL);
               CreateFromAuthorizationCodeParameters param = new CreateFromAuthorizationCodeParameters();

            // code you will get back as part of the url after redirection
               param.setCode("wm7qvCMoGwMbtuytIQPhpGn9Gac7nmwVraQIgNp9uQIovP5c-wGn8oB0LmUnhlhse4at4T8XGwXufb7D94YWgIsZpBSzXMwdFkxp4u2oH9dy3HW4");
               Tokeninfo info = Tokeninfo.CreateFromAuthorizationCode(apiContext, param);
               UserinfoParameters userinfoParams = new UserinfoParameters();
               userinfoParams.setAccessToken(info.access_token);
               Userinfo userinfo = Userinfo.GetUserinfo(apiContext, userinfoParams);
        }
Пример #4
0
 /// <summary>
 /// Creates an Access Token from an Authorization Code.
 /// <param name="apiContext">APIContext to be used for the call.</param>
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
 /// </summary>
 public static Tokeninfo CreateFromAuthorizationCode(APIContext apiContext, CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     string pattern = "v1/identity/openidconnect/tokenservice ?grant_type={0}&code={1}&redirect_uri={2}";
     object[] parameters = new object[] { createFromAuthorizationCodeParameters };
     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);
 }
Пример #5
0
 /// <summary>
 /// Creates an Access Token from an Authorization Code.
 /// <param name="createFromAuthorizationCodeParameters">Query parameters used for API call</param>
 /// </summary>
 public static Tokeninfo CreateFromAuthorizationCode(CreateFromAuthorizationCodeParameters createFromAuthorizationCodeParameters)
 {
     string pattern = "v1/identity/openidconnect/tokenservice?grant_type={0}&code={1}&redirect_uri={2}";
     object[] parameters = new object[] { createFromAuthorizationCodeParameters };
     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 (createFromAuthorizationCodeParameters.getClientId() != null && createFromAuthorizationCodeParameters.getClientSecret() != null)
     {
     OAuthTokenCredential oauthTokenCredential = new OAuthTokenCredential(createFromAuthorizationCodeParameters.getClientId(), createFromAuthorizationCodeParameters.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);
 }