As @ brock-allen said, user service is the right way. So I continued and implemented a simple UserService
public class UserService { private static InMemoryUserService _service = null; public static InMemoryUserService Get() { if(_service == null) _service = new InMemoryUserService(Users.Get()); return _service; } }
registered my service in my factory like this
public void Configuration(IAppBuilder app) { AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject; JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); var factory = InMemoryFactory.Create( users: Users.Get(), clients: Clients.Get(), scopes: Scopes.Get()); factory.UserService = new Registration<IUserService>(resolver => UserService.Get()); .....
(Of course, that setting method is inside my launch class)
So, now I can authenticate the external user in the authentication callback of the external provider (in this case facebook), indicating all the claims I need:
var facebookOptions = new FacebookAuthenticationOptions() { AuthenticationType = "Facebook", Caption = "Sign in with Facebook", AppId = "******", AppSecret = "*******", SignInAsAuthenticationType = signInAsType, Provider = new FacebookAuthenticationProvider() { OnAuthenticated = (context) => { foreach (var x in context.User) { context.Identity.AddClaim(new Claim(x.Key, x.Value.ToString())); } ExternalIdentity identity = new ExternalIdentity() { Claims = context.Identity.Claims, Provider = "Facebook", ProviderId = "Facebook" }; SignInMessage signInMessage = new SignInMessage(); UserService.Get().AuthenticateExternalAsync(identity, signInMessage); return Task.FromResult(context); } }, }
Now i can do
List<Claim> claims = await UserService.Get().GetProfileDataAsync(User as ClaimsPrincipal) as List<Claim>;
And look that my User has all facebook requirements provided during authentication. Of course, this code is only for testing, it can be significantly improved.