minor fixes

minor fixes and updated demo app to accept email address as user name
This commit is contained in:
genuinebasil
2014-09-22 13:57:25 +10:00
parent 32c00daad9
commit 865e20f2e8
7 changed files with 24 additions and 31 deletions

View File

@@ -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;

View File

@@ -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<KeyValuePair<string, string>>();
body.Add(new KeyValuePair<string, string>("code", code));
body.Add(new KeyValuePair<string, string>("redirect_uri", redirectUri));
body.Add(new KeyValuePair<string, string>("client_id", Options.ClientId));
body.Add(new KeyValuePair<string, string>("client_secret", Options.ClientSecret));
body.Add(new KeyValuePair<string, string>("grant_type", "authorization_code"));
var body = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("code", code),
new KeyValuePair<string, string>("redirect_uri", redirectUri),
new KeyValuePair<string, string>("client_id", Options.ClientId),
new KeyValuePair<string, string>("client_secret", Options.ClientSecret),
new KeyValuePair<string, string>("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(

View File

@@ -13,22 +13,16 @@ namespace Owin.Security.Providers.Salesforce
/// <summary>
/// Endpoint which is used to redirect users to request Salesforce access
/// </summary>
/// <remarks>
/// Defaults to https://login.salesforce.com/services/oauth2/authorize
/// </remarks>
public string AuthorizationEndpoint { get; set; }
/// <summary>
/// Endpoint which is used to exchange code for access token
/// </summary>
/// <remarks>
/// Defaults to https://login.salesforce.com/services/oauth2/token
/// </remarks>
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 = "";
/// <summary>
/// Gets or sets the a pinned certificate validator to use to validate the endpoints used

View File

@@ -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"
});
}
}

View File

@@ -23,6 +23,8 @@ namespace OwinOAuthProvidersDemo.Controllers
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
//to support email address as user name
UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false };
}
public UserManager<ApplicationUser> UserManager { get; private set; }