Ich verwende Angular 2 und Auth0 zur Authentifizierung in meiner Web-App. Ich bin in der Lage das Benutzerprofil mit dem folgenden Code zu erhalten:Include user_metadata und app_metadata in JWT mit Auth0
auth0 = new auth0.WebAuth({
domain: 'MY-DOMAIN',
clientID: 'MY-CLIENT-ID',
callbackURL: 'MY-CALLBACK',
responseType: 'token id_token'
});
Anmeldung:
public login(username: string, password: string): void {
this.auth0.client.login({
realm: 'Username-Password-Authentication',
username,
password
}, (err: any, authResult: any) => {
if (err) {
alert('Error: ' + err.description);
return;
}
if (authResult && authResult.idToken && authResult.accessToken) {
this.setUser(authResult); <--- Here is where I get the profile
this.router.navigate(['/home']);
}
});
}
Speicher token
auf localStorage
und bekommt das Profil:
private setUser(authResult: any): void {
localStorage.setItem('access_token', authResult.accessToken);
localStorage.setItem('id_token', authResult.idToken);
this.auth0.client.userInfo(authResult.accessToken, (error: any, profile: any) => {
if (!error) {
localStorage.setItem('profile', JSON.stringify(profile));
this.userProfile = profile;
}
});
}
das funktioniert so, aber Das Profilobjekt, das ich erhalte, enthält nicht die user_metadata oder die app_metadata, die auf der Auth0-Website konfiguriert sind. Wie kann ich es aufnehmen?