From 865e20f2e897cb73741c30ba43b4e90b4a1884d5 Mon Sep 17 00:00:00 2001 From: genuinebasil Date: Mon, 22 Sep 2014 13:57:25 +1000 Subject: [PATCH] minor fixes minor fixes and updated demo app to accept email address as user name --- .../SalesforceAuthenticatedContext.cs | 2 -- .../SalesforceAuthenticationHandler.cs | 29 +++++++++--------- .../SalesforceAuthenticationOptions.cs | 10 ++---- ...-OwinOAuthProvidersDemo-20131113093838.mdf | Bin 3211264 -> 3211264 bytes ...nOAuthProvidersDemo-20131113093838_log.ldf | Bin 1048576 -> 1048576 bytes .../App_Start/Startup.Auth.cs | 12 +++----- .../Controllers/AccountController.cs | 2 ++ 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs b/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs index b42875f..5655e59 100644 --- a/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs +++ b/Owin.Security.Providers/Salesforce/Provider/SalesforceAuthenticatedContext.cs @@ -1,7 +1,5 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. -using System; -using System.Globalization; using System.Security.Claims; using Microsoft.Owin; using Microsoft.Owin.Security; diff --git a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs index 777cf9b..d3d4e98 100644 --- a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs +++ b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationHandler.cs @@ -65,12 +65,14 @@ namespace Owin.Security.Providers.Salesforce string redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; // Build up the body for the token request - var body = new List>(); - body.Add(new KeyValuePair("code", code)); - body.Add(new KeyValuePair("redirect_uri", redirectUri)); - body.Add(new KeyValuePair("client_id", Options.ClientId)); - body.Add(new KeyValuePair("client_secret", Options.ClientSecret)); - body.Add(new KeyValuePair("grant_type", "authorization_code")); + var body = new List> + { + new KeyValuePair("code", code), + new KeyValuePair("redirect_uri", redirectUri), + new KeyValuePair("client_id", Options.ClientId), + new KeyValuePair("client_secret", Options.ClientSecret), + new KeyValuePair("grant_type", "authorization_code") + }; // Request the token var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.Endpoints.TokenEndpoint); @@ -92,11 +94,13 @@ namespace Owin.Security.Providers.Salesforce text = await userResponse.Content.ReadAsStringAsync(); JObject user = JObject.Parse(text); - var context = new SalesforceAuthenticatedContext(Context, user, accessToken); - context.Identity = new ClaimsIdentity( - Options.AuthenticationType, - ClaimsIdentity.DefaultNameClaimType, - ClaimsIdentity.DefaultRoleClaimType); + var context = new SalesforceAuthenticatedContext(Context, user, accessToken) + { + Identity = new ClaimsIdentity( + Options.AuthenticationType, + ClaimsIdentity.DefaultNameClaimType, + ClaimsIdentity.DefaultRoleClaimType) + }; if (!string.IsNullOrEmpty(context.UserId)) { @@ -180,9 +184,6 @@ namespace Owin.Security.Providers.Salesforce // OAuth2 10.12 CSRF GenerateCorrelationId(properties); - // comma separated - //string scope = string.Join(",", Options.Scope); - string state = Options.StateDataFormat.Protect(properties); string authorizationEndpoint = string.Format( diff --git a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationOptions.cs b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationOptions.cs index c6529dc..490e900 100644 --- a/Owin.Security.Providers/Salesforce/SalesforceAuthenticationOptions.cs +++ b/Owin.Security.Providers/Salesforce/SalesforceAuthenticationOptions.cs @@ -13,22 +13,16 @@ namespace Owin.Security.Providers.Salesforce /// /// Endpoint which is used to redirect users to request Salesforce access /// - /// - /// Defaults to https://login.salesforce.com/services/oauth2/authorize - /// public string AuthorizationEndpoint { get; set; } /// /// Endpoint which is used to exchange code for access token /// - /// - /// Defaults to https://login.salesforce.com/services/oauth2/token - /// public string TokenEndpoint { get; set; } } - private const string AuthorizationEndPoint = "https://login.salesforce.com/services/oauth2/authorize"; - private const string TokenEndpoint = "https://login.salesforce.com/services/oauth2/token"; + private const string AuthorizationEndPoint = ""; + private const string TokenEndpoint = ""; /// /// Gets or sets the a pinned certificate validator to use to validate the endpoints used diff --git a/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838.mdf b/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838.mdf index b7224c05d47760f5001040e5aa3f29cb79f1f86d..1a84f29fd55400b75294c5d465ff7cab551e9e3a 100644 GIT binary patch delta 2064 zcmcgtT}&KR6ux(Mb{U4+0<*Bd!m`V*6xaoqf7qIOv8LAA_(Q3UX{p1~#cB%}pqi*D zn3&mwm^2MB*S<6~Ha<2~YsaWj)J922eP|+o{sa?ae2{3{XthT4yE8k@8skef-ji?k z+;hKs?m1`9+?|-XNGAl&(^$~^EFpvf&N%n|zVuYrM^$DrNDt7ESe78!BZP@Jj;FHq( zMP5NuvS`2EO;UoE)+Z!WpK#5MTi$koB4^P)368A^+MBwZPuus9QIaAfcMS+Ve*FaxiaA)YE`~oGspjPRmCHBp)Bzt9UJU{P|jImt_s^ zR%AY1s|4WY#G>lsGlL$Puh@oP#dbt<6x(;!DOHaCqOG5cDL$^R=E;0)z=>$7PWjQH ztwxpo89m(-Q-EBvC#EhF#Rhh9f~ zHx|??5TN^c$D$grb)>f_>?U#u(ToHB)sngqdgJG6ROlWaSXLDn9y|j_`ikmJcQ30z z9;kb13u5wW~hBQ-BpaKX0l|T>(nTgX?^XrMEb5l7VJSBVK@MIv* zU4ha%)fIP1X@oWaX@T_P=4i5{pR_{$dc!2KZxr{*5fa5s^Ne-xFmMLR zo<7Um00+aEwt^^JrQkje*Y#Eqoj5=o--ZJYW{yu`y&kg;i`|4>oqz}{N#gvDUziQMgIoSqL5cKYhbM4NuFR_7Vc10R>fsM|4sRJqYg)q*(f{?Maqh{0|*Shc}68?44)wFav*Skz!KgVh_X M!C-g1#^SSo0{o=1fdBvi delta 1286 zcmZuwTWAwO6y4d~Y$w}Vn{Jx)5!2l?wXfJJ6nyK5Afg{)EtW#7t55}@B31u{29yc( zLr{@XKP2J<(GROsw}@zcfJH$;#Wb8s|C^Bwf_xR9ls!G)*Az@pRr|@=COv) z7p(yq-74mhem3-e)M1-qk&3X@yGy)NW{WP%qy4;B z+rw!IGcHaMlzmO+wyvV&f#N5 z8?Iu5ePW42c~XxtyOr@^_HA18vzeD3XT!_C14n@Q8t`HiU>o;{LAJXC`<)jLG{B25 z(m*%&h?wb{u*{MTIE;MkNJ z!_8}~5r1}R*(ThTvlHzx4Ded*F?H;ieG)n(>5j|&Po6nnVnkgVK$vYyt4*^@`8MLs z!hxA_4f6Z(QjGus>?*b>rG_0FDok;|1vMBbC%`7g)MBs~yi%LEt*~%f#o*X*4us5% z>QA(#RX`!22rvs!444flvD(tUjAEzCJJcN?wdqc$X|g`c%$D9-86B@|D?bVQ&^H2a zN8UjE&<1jSp1M@KGk4C~m!P#`xprH$1|x+ZWO=IWs749={FIbY5}+hVNjW7IlvGku zb%TUrrkz3r^xW~fS^CZOn3)W9+joIIOosZ9kXUji1egN|1F8W!z_6B_i9DWJ8nH73 z6}P*Q&;d_Z!iqcxQs(I!0Dc!0fF{8L-c5sN4?5{5YfebsdYkHnt2!BtRzOd7sS`LT zIrGLyjYt1qpl*;lAKoli{}afY7wGN0irjt3*1UHE75)vRPfCYzx8%&BXnq`?Iv+^b z3hTx2I@$Oq4zI;6s5w!2Gj|@*aW{^dALkTqmz+sSl#*IX=2B8eNj)VElr&P(L`jU2 Od6YC$(sF^!ANd1wZas7W diff --git a/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838_log.ldf b/OwinOAuthProvidersDemo/App_Data/aspnet-OwinOAuthProvidersDemo-20131113093838_log.ldf index 681ba07ce70f15f3b17488dd8589e596f36d29bc..6d2e671ac87dec7b092d74fa8c2011d5ad6ca59d 100644 GIT binary patch delta 8936 zcmeHLYjhRW72anackaEJgd1`bLVzSU0to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hvpK<_BC*VY%W81$3;_pr>e;_h9saz&B z;$Ipo7JHJ)cqw)8Z<{ND#(jtGZ!E&h`xxunm5#qcg9|~&dYMCcv%+7 zuNeNVE*uN^m*5y&Rw1a0kHRJx|IFK0?AOlje%0%7TcMv!NB;_2e|L3Asb~MmclG~F zeUhVorL8`hg^FW4i%7xj#V%Xmm$psh3_0fAS$X(}mSfjRBZcuVMyjdJq3NuRwcpzr dXlJ0Efp!Mk8E9vqoq=`++8K}xaLf|d0EjCd>hGlE@nHiG{B^5R%Y+~7bNx+m*O@V=dp#+H47?^-00w@5P z5OD^Ei%gq+dG@g?>I21`(bOpd#USDg48ogp*!B~rY&R>hHuFlnXJ=Y1(ELxn{hvG| z5HkTWGZ3=?F)I+W0Wmuea{w_X5OV=B_x6ACJWNK@Kie>iZf=m=&NNDlhQVk$7|jNw OMZsuEI2235sZ0RhV(=vZ diff --git a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs index 12c3d7d..6b1f77a 100755 --- a/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs +++ b/OwinOAuthProvidersDemo/App_Start/Startup.Auth.cs @@ -80,21 +80,19 @@ namespace OwinOAuthProvidersDemo // Use OpenId provider login uri instead of discovery uri //app.UseOpenIDAuthentication("http://openid.orange.fr/server", "Orange", true); - app.UseSalesforceAuthentication("", ""); - //in scenarios where a sandbox URL needs to be used app.UseSalesforceAuthentication(new SalesforceAuthenticationOptions { Endpoints = - new Owin.Security.Providers.Salesforce.SalesforceAuthenticationOptions. + new SalesforceAuthenticationOptions. SalesforceAuthenticationEndpoints { AuthorizationEndpoint = - "https://cs5.salesforce.com/services/oauth2/authorize", - TokenEndpoint = "https://cs5.salesforce.com/services/oauth2/token" + "https://ap1.salesforce.com/services/oauth2/authorize", + TokenEndpoint = "https://ap1.salesforce.com/services/oauth2/token" }, - ClientId = "", - ClientSecret = "" + ClientId = "3MVG9Y6d_Btp4xp5epd3nPl2fNfrMmM4AALkiggjcPPqIaZk3gwisao_ysPAO0VtTmD3yjn3kmXeoH12pQu9M", + ClientSecret = "2096527102750431971" }); } } diff --git a/OwinOAuthProvidersDemo/Controllers/AccountController.cs b/OwinOAuthProvidersDemo/Controllers/AccountController.cs index 1faa5d6..4e544a9 100644 --- a/OwinOAuthProvidersDemo/Controllers/AccountController.cs +++ b/OwinOAuthProvidersDemo/Controllers/AccountController.cs @@ -23,6 +23,8 @@ namespace OwinOAuthProvidersDemo.Controllers public AccountController(UserManager userManager) { UserManager = userManager; + //to support email address as user name + UserManager.UserValidator = new UserValidator(UserManager) { AllowOnlyAlphanumericUserNames = false }; } public UserManager UserManager { get; private set; }