I am trying to use Microsoft Account as an external login with IdentityServer4 , I configured my app under Microsoft Application portal as needed , I added a web platform and added "email" under Delegated Permissions to be able to read it, and here is my code to access Microsoft Account :
.AddMicrosoftAccount("MicrosoftAccount", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.ClientId = "ClientId";
options.ClientSecret = "ClientSecret";
options.Scope.Add("openid");
options.Scope.Add("email");
});
when I run the application everything works fine and after the user enter his username and password a confirmation message appears to grant my app a permission to access the email address , but when I checked the retrieved claims inside a custom ProfileService
using context.Subject.Claims
, I did not find any claim contains the email address , so any help how can I get it .
Here is a sample of code that shows how I access the claims inside GetProfileDataAsync method :
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var claims = context.Subject.Claims; // => there is no claim for the email address
claims = claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();
context.IssuedClaims = claims.ToList();
}
based on @serpent5 advise I wrote a sample code to show the problem and upload it to githug ,
the sample code contains 3 projects
- Fiver.Security.AuthServer (Identity Server)
- Fiver.Security.AuthServer.Client (client)
- Fiver.Security.AuthServer.Api (secured API the client wants to access)
I took the original code from this article
https://www.codeproject.com/Articles/1205745/Identity-Server-with-ASP-NET-Core
as I said above , the problem is that I added the email as a scope but it is not returned as a claim from Microsoft account after logging-in ..