В программе.
Код: Выделить всё
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = FakeAuthHandler.SchemeName;
options.DefaultChallengeScheme = FakeAuthHandler.SchemeName;
}).AddScheme(
FakeAuthHandler.SchemeName,
displayName: FakeAuthHandler.SchemeName,
configureOptions: _ => { }
);
< /code>
fakeauthhandler выглядит так: < /p>
public class FakeAuthHandler : AuthenticationHandler
{
public const string SchemeName = "TestProvider";
public FakeAuthHandler(IOptionsMonitor options,
ILoggerFactory logger, UrlEncoder encoder)
: base(options, logger, encoder) { }
protected override Task HandleAuthenticateAsync()
{
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, "TestExternalUser"),
new Claim(ClaimTypes.Name, "Test User"),
new Claim(ClaimTypes.Email, "testuser@example.com"),
new Claim("urn:google:profile", "https://profiles.google.com/testuser"),
};
var identity = new ClaimsIdentity(claims, SchemeName);
var principal = new ClaimsPrincipal(identity);
var ticket = new AuthenticationTicket(principal, SchemeName);
return Task.FromResult(AuthenticateResult.Success(ticket));
}
}
< /code>
конечная точка выглядит так: < /p>
[HttpGet("/api/auth/external-login")]
[AllowAnonymous]
public async Task ExternalLogin(string provider, string returnUrl = null)
{
var redirectUrl = _linkGenerator.GetPathByAction(
action: nameof(AuthController.ExternalLoginCallback),
controller: "Auth",
values: new { returnUrl = request.ReturnUrl }
);
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
Проблема в том, что/API/Auth/versemplo-login возвращает 401 и не перенаправляет путь к обращению. Я даже не уверен, как проверить, где проблема. Я что -то пропустил?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... -challenge