From f17ae032c4d42976e9a10b0807d5738f1159ac1c Mon Sep 17 00:00:00 2001 From: scottedwardhill Date: Wed, 16 Jul 2014 17:14:22 -0400 Subject: [PATCH] support for refresh token in Salesforce provider --- .../Provider/SalesforceAuthenticatedContext.cs | 9 ++++++++- .../Salesforce/SalesforceAuthenticationHandler.cs | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs b/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs index b42875f..3d2c436 100644 --- a/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs +++ b/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs @@ -21,11 +21,13 @@ namespace Owin.Security.Providers.Salesforce /// The OWIN environment /// The JSON-serialized user /// Salesforce Access token - public SalesforceAuthenticatedContext(IOwinContext context, JObject user, string accessToken) + /// Salesforce Refresh token + public SalesforceAuthenticatedContext(IOwinContext context, JObject user, string accessToken, string refreshToken) : base(context) { User = user; AccessToken = accessToken; + RefreshToken = refreshToken; Id = TryGetValue(user, "id"); UserId = TryGetValue(user, "user_id"); @@ -54,6 +56,11 @@ namespace Owin.Security.Providers.Salesforce /// public string AccessToken { get; private set; } + /// + /// Gets the Salesforce refresh token, if the application's scope allows it + /// + public string RefreshToken { get; private set; } + /// /// Gets the Salesforce ID / User Info Endpoint /// diff --git a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs index 777cf9b..faf5b16 100644 --- a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs +++ b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs @@ -83,6 +83,7 @@ namespace Owin.Security.Providers.Salesforce // Deserializes the token response dynamic response = JsonConvert.DeserializeObject(text); string accessToken = (string)response.access_token; + string refreshToken = (string)response.refresh_token; // Get the Salesforce user using the user info endpoint, which is part of the token - response.id HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, (string)response.id + "?access_token=" + Uri.EscapeDataString(accessToken)); @@ -92,7 +93,7 @@ namespace Owin.Security.Providers.Salesforce text = await userResponse.Content.ReadAsStringAsync(); JObject user = JObject.Parse(text); - var context = new SalesforceAuthenticatedContext(Context, user, accessToken); + var context = new SalesforceAuthenticatedContext(Context, user, accessToken, refreshToken); context.Identity = new ClaimsIdentity( Options.AuthenticationType, ClaimsIdentity.DefaultNameClaimType,