在授权URL中具有自定义属性的网络核心MVC OAuth

时间:2018-10-01 13:47:26

标签: c# asp.net-core oauth-2.0 asp.net-core-mvc

我正在尝试制作一个.net核心MVC客户端应用程序,使用oAuth2获取令牌以访问某些受保护的API。

授权URL需要以下URL参数:

  • 范围
  • response_type
  • redirect_uri
  • client_id
  • unit_reference

除了“ unit_reference”之外,我知道如何设置它们中的大多数。这是一个自定义授权参数。

URL应该如下所示: https://auth.test.com/Account/Login?scope=acc&unit_reference=9999&response_type=code&redirect_uri=https%3A%2F%2Flocalhost&client_id=ffffffff-ffff-ffff-ffff-fffffffff&state=state_this

到目前为止,这是我在Startup.cs ConfigureServices中的代码:

services.AddAuthentication(options =>
{
    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    options.DefaultChallengeScheme = "AccessProvider";
})
.AddCookie()
.AddOAuth("AccessProvider", options =>
{
    options.ClientId = Configuration["AccessProvider:ClientId"];
    options.ClientSecret = Configuration["AccessProvider:ClientSecret"];
    options.CallbackPath = new PathString("/Account");
    options.Scope.Add("acc");

    // Missing unit_reference

    options.AuthorizationEndpoint = "https://auth.test.com/Account/Login";
    options.TokenEndpoint = "https://auth.test.com/Token";

    options.SaveTokens = true;
});

0 个答案:

没有答案
相关问题