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); }
/// <summary> /// Returns user details /// <param name="apiContext">APIContext to be used for the call.</param> /// <param name="userinfoParameters">Query parameters used for API call</param> /// </summary> public static Userinfo GetUserinfo(APIContext apiContext, UserinfoParameters userinfoParameters) { string pattern = "v1/identity/openidconnect/userinfo?schema={0}&access_token={1}"; object[] parameters = new object[] { userinfoParameters }; string resourcePath = SDKUtil.FormatURIPath(pattern, parameters); if (apiContext == null) { apiContext = new APIContext(); } apiContext.MaskRequestId = true; return(PayPalResource.ConfigureAndExecute <Userinfo>(apiContext, HttpMethod.GET, resourcePath)); }
public void TestUserinfoDynamic() { Dictionary <string, string> configurationMap = new Dictionary <string, string>(); configurationMap.Add("clientId", ""); configurationMap.Add("clientSecret", ""); configurationMap.Add("mode", "live"); APIContext apiContext = new APIContext(); apiContext.Config = configurationMap; UserinfoParameters userinfoParams = new UserinfoParameters(); userinfoParams.SetAccessToken(info.access_token); Userinfo userinfo = Userinfo.GetUserinfo(apiContext, userinfoParams); Assert.AreEqual(userinfo != null, true); }
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 { 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; } }
public void TestUserinfoDynamic() { Dictionary<string, string> configurationMap = new Dictionary<string, string>(); configurationMap.Add("clientId", ""); configurationMap.Add("clientSecret", ""); configurationMap.Add("mode", "live"); APIContext apiContext = new APIContext(); apiContext.Config = configurationMap; UserinfoParameters userinfoParams = new UserinfoParameters(); userinfoParams.SetAccessToken(info.access_token); Userinfo userinfo = Userinfo.GetUserinfo(apiContext, userinfoParams); Assert.AreEqual(userinfo != null, true); }
/// <summary> /// Returns user details /// <param name="apiContext">APIContext to be used for the call.</param> /// <param name="userinfoParameters">Query parameters used for API call</param> /// </summary> public static Userinfo GetUserinfo(APIContext apiContext, UserinfoParameters userinfoParameters) { string pattern = "v1/identity/openidconnect/userinfo?schema={0}&access_token={1}"; object[] parameters = new object[] { userinfoParameters }; string resourcePath = SDKUtil.FormatURIPath(pattern, parameters); if (apiContext == null) { apiContext = new APIContext(); } apiContext.MaskRequestId = true; return PayPalResource.ConfigureAndExecute<Userinfo>(apiContext, HttpMethod.GET, resourcePath, setAuthorizationHeader: false); }
/// <summary> /// Returns user details /// <param name="userinfoParameters">Query parameters used for API call</param> /// </summary> public static Userinfo GetUserinfo(UserinfoParameters userinfoParameters) { return GetUserinfo(null, userinfoParameters); }
/// <summary> /// Returns user details /// <param name="userinfoParameters">Query parameters used for API call</param> /// </summary> public static Userinfo GetUserinfo(UserinfoParameters userinfoParameters) { return(GetUserinfo(null, userinfoParameters)); }