我获得了一个用作身份提供者的URL(使用Open connect id协议),我只需要能够使用此提供者登录。
我遇到的问题是当我尝试登录时,我在浏览器中获取此URL,并在一秒钟之后再次重定向到我的localhost,无法登录:
这就是我在创建Web应用程序时所做的:
{
"AzureAdB2C": {
"Instance": "https://sitekitdev.b2clogin.com/tfp/",
"ClientId": "6e093bdb-ba93-4c02-83fb-77678f07b14b",
"CallbackPath": "/signin-oidc",
"Domain": "sitekitdev.onmicrosoft.com",
"SignUpSignInPolicyId": "B2C_1_Signuporin",
"ResetPasswordPolicyId": "All",
"EditProfilePolicyId": ""
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
然后我没有改变别的,做所有的默认网页。
我必须使用的身份提供者端点:
注意:我在浏览器中获得的第一个URL与此有点不同,在第一个URL中我没有第一部分login.microsoftonline.com
这是我的初创班:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
我只需要能够登录,然后返回JWT(我将在能够看到登录页面后进行配置)。
谢谢
对于代码,您可以参考这个demo。
或者您可以直接使用url get请求让用户登录然后返回令牌。
https://tenantname.b2clogin.com/tenantname.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_sample-sign-up-in&client_id=<value>&nonce=defaultNonce&redirect_uri=https%3A%2F%2Fjwt.io&scope=openid&response_type=id_token&prompt=login
它将重定向到登录页面:
用户登录后,它将重定向到您的页面(此处以jwt为例)。
对于B2C中的openid连接,您可以阅读here。