संदर्भ: मैं ओविन स्वयं होस्ट के साथ एएसपी.नेट एमवीसी का उपयोग कर रहा हूं। नीचे बाकी कॉन्फ़िगरेशन/सेटअप हैं।पहचान सर्वर 3: कुछ दावा पहचान सर्वर से वापस नहीं लौटाए जा रहे हैं
पहचान सर्वर में मेरी ग्राहक रों में (AllowedScopes सेट दिखाई):
public static class InMemoryClientSource
{
public static List<Client> GetClientList()
{
return new List<Client>()
{
new Client()
{
ClientName = "Admin website",
ClientId = "admin",
Enabled = true,
Flow = Flows.Hybrid,
ClientSecrets = new List<Secret>()
{
new Secret("admin".Sha256())
},
RedirectUris = new List<string>()
{
"https://admin.localhost.com/"
},
PostLogoutRedirectUris = new List<string>()
{
"https://admin.localhost.com/"
},
AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
Constants.StandardScopes.Roles
}
}
};
}
}
यहाँ कार्यक्षेत्र हैं:
public static class InMemoryScopeSource
{
public static List<Scope> GetScopeList()
{
var scopes = new List<Scope>();
scopes.Add(StandardScopes.OpenId);
scopes.Add(StandardScopes.Profile);
scopes.Add(StandardScopes.Email);
scopes.Add(StandardScopes.Roles);
return scopes.ToList();
}
}
पहचान सर्वर में, यहां बताया गया है कि सर्वर कैसे कॉन्फ़िगर किया गया है। (ध्यान दें ग्राहकों और कार्यक्षेत्र लोगों ऊपर प्रदान की जाती हैं):
var userService = new UsersService(.... repository passed here ....);
var factory = new IdentityServerServiceFactory()
.UseInMemoryClients(InMemoryClientSource.GetClientList())
.UseInMemoryScopes(InMemoryScopeSource.GetScopeList());
factory.UserService = new Registration<IUserService>(resolver => userService);
var options = new IdentityServerOptions()
{
Factory = factory,
SigningCertificate = Certificates.Load(), // certificates blah blah
SiteName = "Identity"
};
app.UseIdentityServer(options);
अंत में, ग्राहक वेब अनुप्रयोग तरफ, यह कैसे प्रमाणन सेट किया गया है:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions()
{
Authority = "https://id.localhost.com",
ClientId = "admin",
RedirectUri = "https://admin.localhost.com/",
PostLogoutRedirectUri = "https://admin.localhost.com/",
ResponseType = "code id_token token",
Scope = "openid profile email roles",
ClientSecret = "admin",
SignInAsAuthenticationType = "Cookies"
});
मेरे पास है
public class UsersService : UserServiceBase
{
public UsersService(.... repository passed here ....)
{
//.... ctor stuff
}
public override Task AuthenticateLocalAsync(LocalAuthenticationContext context)
{
// var user = .... retrieved from database .....
// ... auth logic ...
if (isAuthenticated)
{
var claims = new List<Claim>();
claims.Add(new Claim(Constants.ClaimTypes.GivenName, user.FirstName));
claims.Add(new Claim(Constants.ClaimTypes.FamilyName, user.LastName));
claims.Add(new Claim(Constants.ClaimTypes.Email, user.EmailAddress));
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.EmailAddress, claims);
}
return Task.FromResult(0);
}
}
जैसा कि आप देख, का दावा है इस पंक्ति में पारित कर रहे हैं: IUserService के लिए एक कस्टम वर्ग कार्यान्वित:
context.AuthenticateResult = new AuthenticateResult(user.Id.ToString(), user.EmailAddress, claims);
जब मैं पहचान सर्वर 3 में लॉग इन करने का प्रयास करता हूं, तो मैं क्लाइंट वेब एप्लिकेशन में सफलतापूर्वक लॉग इन कर सकता हूं। हाउवर, जब मुझे उपयोगकर्ता का दावा मिलता है, तो मुझे कोई पहचान दावा नहीं दिखता है। नहीं दिया_name, family_name, और ईमेल दावे। नीचे स्क्रीनशॉट:
कुछ भी मैं याद किया हो सकता है? अग्रिम में धन्यवाद!
आपका विन्यास ठीक लग रहा है:
एक में स्मृति ग्राहक सब मैंने किया था के लिए कुछ इस तरह था। मूर्खतापूर्ण मुझे पता है, लेकिन क्या आप निश्चित हैं कि प्रमाणीकृत उपयोगकर्ता के पास ये दावा हैं? –
अरे @ स्कॉटब्राडी, मुझे लगता है कि वे पहले से ही हैं क्योंकि मैंने संदर्भ में उन दावों को जोड़ा है। प्रमाणीकरण रीसेट (जैसा कि आप कस्टम उपयोगकर्ता सेवा कार्यान्वयन के लिए उपरोक्त नमूना कोड पर देखते हैं)। – jerbersoft