Answer the question
In order to leave comments, you need to log in
How to implement the following bundle - IdentityServer4 + WebApi + Angular2 + External Auth?
Hello, I'm trying to do the following:
WEB API separate domain
IdentityServer4 API separate domain
Angular 2 Client separate
Mobile APP domain.
Angular 2 client authorizes with an External service (Twitter)
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Debug);
app.UseCors("CorsPolicy");
app.UseIdentity();
app.UseIdentityServer();
//after identity before mvc
app.UseTwitterAuthentication(new TwitterOptions
{
AuthenticationScheme = "Twitter",
DisplayName = "Twitter",
SignInScheme = "Identity.External",
ConsumerKey = "key",
ConsumerSecret = "secret",
AutomaticAuthenticate = true,
AutomaticChallenge = true,
SaveTokens = true,
});
app.UseMvc();
}
bool result = false;
var info = await signInManager.GetExternalLoginInfoAsync();
if (info != null)
{
var tempUser = info.Principal;
var claims = tempUser.Claims.ToList();
var userIdClaim = claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);
var email = claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email);
if (userIdClaim != null)
{
var isRegistered = await IsUserRegistered(info.LoginProvider, info.ProviderKey);
if (!isRegistered && email != null)
{
var user = new ApplicationUser { UserName = userIdClaim.Value, Email = email.Value };
var userCreated = await userManager.CreateAsync(user);
isRegistered = userCreated.Succeeded;
if (isRegistered)
{
var addLoginresult = await userManager.AddLoginAsync(user, info);
isRegistered = addLoginresult.Succeeded;
if (isRegistered)
{
await signInManager.SignInAsync(user, isPersistent: false);
}
}
}
if (isRegistered)
{
var succeded = await signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false);
if (succeded.Succeeded)
{
IdentityResult updateResult = await signInManager.UpdateExternalAuthenticationTokensAsync(info);
result = updateResult.Succeeded;
}
}
}
}
if (!result)
{
await signInManager.SignOutAsync();
}
return Redirect(System.Net.WebUtility.UrlDecode(returnUrl));
Answer the question
In order to leave comments, you need to log in
For now, I haven't been able to figure it out.
But perhaps the problem is that I receive an external token from twitter,
and I need to somehow get the internal token issued by ID4 and already use it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question