Ich verwende identityserver3 für die Authentifizierung OpenIDConnect verwenden. Ich habe bemerkt, dass IdentityServer3 die Profilinformationen des Benutzers zurückgibt, auch wenn der Benutzer keine Einwilligung gegeben hat. Ich bin mir nicht sicher, ob dieses Standardverhalten oder es ein Fehler ist. Es passiert, wenn ich Clients, Scope und Benutzer mit EF und AspNetIdentity konfiguriert habe. Diese ist, wie ich die IdentityServer konfiguriertIdentityServer3 gibt Benutzerprofilinformationen ohne Zustimmung des Benutzers
Benutzer
Properties
UserName: Someusername
Password: SomePassword
Email: [email protected]
Phone:1234567
Claims:
Country: US
TimeZoneID: CST
Scope (OpenID)
Name: openid
Enabled: true
Type: 0 (ie. Identity)
Kunde
AbsoluteRefreshTokenLifeTime: 300
AccessTokenLifeTime: 7200
ClientID: LocalHostMvcClient
Client Name: Local Host Client
Enabled: true
EnableLocalLoging: true
IdentityTokenLifetimne:300
PrefixClientClaims: true
RequireConsent:true
AllowAccessTokenViaBrowser:true
Scopes: openid
Beachten Sie, dass kein profile
Scope hinzugefügt wurde. Dies bedeutet, dass der Client Profilinformationen nicht anfordern kann und der Benutzer keine Profilinformationen zusagen kann. Der Benutzer kann nur Identitätsinformationen zustimmen.
I haben, wie unten
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44314/identity",
Scope = "openid",
ClientId = "LocalHostMvcClient",
RedirectUri = "http://localhost:34937/",
ResponseType = "id_token token",
SignInAsAuthenticationType = "Cookies",
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = async n =>
{
var nid = new ClaimsIdentity(n.AuthenticationTicket.Identity.AuthenticationType);
// get userinfo data
var userInfoClient = new UserInfoClient(
new Uri(n.Options.Authority + "/connect/userinfo"),
n.ProtocolMessage.AccessToken);
var userInfo = await userInfoClient.GetAsync();
userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2)));
n.AuthenticationTicket = new AuthenticationTicket(
nid,
n.AuthenticationTicket.Properties);
}
}
});
}
dem Client konfiguriert I erwartete userInfoClient.GetAsync()
wird preferred_username
und sub
Ansprüche nur zurück. Es gibt jedoch auch alle Profilinformationen des Benutzers zurück. Wie Telefonnummer, E-Mail, Land und TimeZoneID. Ich habe dieses Verhalten bemerkt geschieht nur, wenn ich Benutzer konfiguriert, Spektive und Kunden in SQL EF mit & AspNetIdentity. Ich sehe dies geschieht nicht, wenn ich im Speicher konfiguriert
Update1(Ausgabe gemäß Brock Allens Antwort Below)
public class UserService : AspNetIdentityUserService<User, string>
{
public UserService(UserManager userMgr)
: base(userMgr)
{
}
}
public class AspNetIdentityUserService<TUser, TKey> : UserServiceBase
where TUser : class, Microsoft.AspNet.Identity.IUser<TKey>, new()
where TKey : IEquatable<TKey>
{
..
..
..
..
public override async Task GetProfileDataAsync(ProfileDataRequestContext ctx)
{
var subject = ctx.Subject;
var requestedClaimTypes = ctx.RequestedClaimTypes;
if (subject == null) throw new ArgumentNullException("subject");
TKey key = ConvertSubjectToKey(subject.GetSubjectId());
var acct = await userManager.FindByIdAsync(key);
if (acct == null)
{
throw new ArgumentException("Invalid subject identifier");
}
var claims = await GetClaimsFromAccount(acct);
if (requestedClaimTypes != null && requestedClaimTypes.Any())
{
claims = claims.Where(x => requestedClaimTypes.Contains(x.Type));
}
ctx.IssuedClaims = claims;
}
}
Update2
Die folgende Update scheint zu funktionieren mich.
public override async Task GetProfileDataAsync(ProfileDataRequestContext ctx)
{
var requestedClaimTypes = ctx.RequestedClaimTypes;
if (requestedClaimTypes != null && requestedClaimTypes.Any())
{
var subject = ctx.Subject;
if (subject == null) throw new ArgumentNullException("subject");
TKey key = ConvertSubjectToKey(subject.GetSubjectId());
var acct = await userManager.FindByIdAsync(key);
if (acct == null)
{
throw new ArgumentException("Invalid subject identifier");
}
var claims = await GetClaimsFromAccount(acct);
claims = claims.Where(x => requestedClaimTypes.Contains(x.Type));
ctx.IssuedClaims = claims;
}
}
Allerdings habe ich auch ein weiteres Problem bemerkt. Auf profile
Umfang selbst wenn gesetzt i IncludeAllCliamsForUser
zu true
, noch in GetProfileDataAsync
Methode ctx.RequestedClaimTypes
null zurückgibt.
So Userinfo Endpunkt keine Ansprüche selbst dann nicht zurück, wenn Client profile
anfordernden diese Funktion zu erhalten, zusätzlich zu den oben fix, ich habe auch explizit Benutzer Ansprüche profile
Rahmen hinzuzufügen und setzen IncludeAllCliamsForUser
zu false
'https: // identityserver.github.io/Dokumentation/docsv2/Endpunkte/userinfo.html' Die Dokumentation für Userinfo Endpunkt sagt:„Das kann Userinfo Endpunkt verwendet werden Identitätsinformationen über ein Thema abzurufen.Es erfordert ein gültiges Zugriffs-Token mit mindestens dem 'openid'-Gültigkeitsbereich. " – LP13
Siehe update1 oben, das ist die aktuelle Implementierung. Sieht so aus, als ob' requestedClaimTypes' null ist und dann alle Ansprüche zurückgibt. – LP13