2017-05-20 13 views
1

我如何像LinkedIn自定义身份验证提供者从出现在SignInManager.GetExternalAuthenticationSchemes()其中Login.cshtml拍摄由默认如何LinkedIn添加到SignInManager.GetExternalAuthenticationSchemes()

背景细节:

我试图理解asp.net核心身份框架。在这一努力中,我创建了一个标准的.NET核心项目

Project Type

Project Type

我尝试了支持Google认证一起阅读documentation,这一切对我来说工作得很好。

我能够为我做LinkedIn验证工作,但无法理解如何使某些部分工作。要添加LinkedIn验证支持,我进行了如下修改

添加了下面线在Startup.Configure方法

app.UseOAuthAuthentication(new OAuthOptions() { 
    AuthenticationScheme = "LinkedIn", 
    ClientId = Configuration["Authentication:LinkedIn:ClientID"], 
    ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"], 
    CallbackPath = new PathString("/signin-linkedin"), 
    AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization", 
    TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken", 
    UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)", 
    Scope = { "r_basicprofile", "r_emailaddress" }, 
}); 

添加了必需的ClientIdClientSecret到配置

增加了以下行到Login.cshtml

<button type="submit" class="btn btn-default" name="provider" value="LinkedIn" title="Log in using your LinkedIn account">LinkedIn</button> 

所有这些工作很好。现在的问题是:
对于支持的认证供应商,当我打电话,说,app.UseGoogleAuthenticationStartup.Configure,我在Login.cshtml列表Google为提供呼叫SignInManager.GetExternalAuthenticationSchemes()。什么我需要做的,所以调用SignInManager.GetExternalAuthenticationSchemes()还将列出LinkedIn作为提供

+2

我相信你已经签出https://auth0.com/blog/authenticating-a-user-with-linkedin-in-aspnet - 核心/? –

+1

@GeoffJames是的,我做到了。它帮助我理解了一堆事情,但不是这个具体问题。没有正式的“asp.net核心”框架文档和类似“身份证”的相关图书馆一直是我最大的敌人 – Vikhram

+0

我想你可能有。只是想我会检查。我同意,这个话题似乎没有太多。只有通常的“如何添加auth提供商...”的东西。我希望你的问题排序:)快乐的编码! –

回答

2

什么我需要做的,所以调用SignInManager.GetExternalAuthenticationSchemes()也将列出LinkedIn作为一个供应商

此方法仅列出已分配“显示名称”的认证中间件。

要在供应商列表中包含链接,设置OAuthOptions.DisplayName

app.UseOAuthAuthentication(new OAuthOptions 
{ 
    DisplayName = "LinkedIn" 
    // ... 
}); 
+0

我已经找到了答案,但是感谢您为其他人发布好处。我很惊讶,没有文件说明这一点。我最终浏览了github代码来解决这个问题(因为核心框架调试并未真正在我的VS 2017中设置)。我想知道你是如何发现这是问题的? – Vikhram

+0

@Vikhram哈哈。好吧,我帮助ASP.NET团队设计了这个通用的OAuth2中间件,所以我很清楚它是如何在内部工作的:) – Pinpoint

+0

这使得很多理解:) – Vikhram