зеркало из https://github.com/mozilla/doorman.git
Adjust email extraction to latest changes (ref #55)
This commit is contained in:
Родитель
59f4883eef
Коммит
bef0e87575
|
@ -9,10 +9,11 @@ import (
|
|||
|
||||
// MozillaClaims uses specific attributes for emails and groups
|
||||
type MozillaClaims struct {
|
||||
Subject string `json:"sub,omitempty"`
|
||||
Audience jwt.Audience `json:"aud,omitempty"`
|
||||
Emails []string `json:"https://sso.mozilla.com/claim/emails,omitempty"`
|
||||
Groups []string `json:"https://sso.mozilla.com/claim/groups,omitempty"`
|
||||
Subject string `json:"sub"`
|
||||
Audience jwt.Audience `json:"aud"`
|
||||
Email string `json:"email"`
|
||||
Emails []string `json:"https://sso.mozilla.com/claim/emails"`
|
||||
Groups []string `json:"https://sso.mozilla.com/claim/groups"`
|
||||
}
|
||||
|
||||
// MozillaAuth0Validator is the implementation of JWTValidator for Auth0.
|
||||
|
@ -39,10 +40,17 @@ func (v *MozillaAuth0Validator) ExtractClaims(request *http.Request) (*Claims, e
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// In case the JWT was not requested with the profile or email scope.
|
||||
email := mozclaims.Email
|
||||
if email == "" && len(mozclaims.Emails) > 0 {
|
||||
email = mozclaims.Emails[0]
|
||||
}
|
||||
|
||||
claims := Claims{
|
||||
Subject: mozclaims.Subject,
|
||||
Audience: mozclaims.Audience,
|
||||
Email: mozclaims.Emails[0],
|
||||
Email: email,
|
||||
Groups: mozclaims.Groups,
|
||||
}
|
||||
return &claims, nil
|
||||
|
|
|
@ -33,4 +33,11 @@ func TestMozillaAuth0ExtractClaims(t *testing.T) {
|
|||
assert.Contains(t, claims.Subject, "|Mozilla-LDAP|")
|
||||
assert.Contains(t, claims.Email, "@mozilla.com")
|
||||
assert.Contains(t, claims.Groups, "cloudservices_dev", "irccloud")
|
||||
|
||||
// Email provided in `email` field instead of https://sso.../emails list
|
||||
r, _ = http.NewRequest("GET", "/", nil)
|
||||
r.Header.Set("Authorization", "Bearer eyJ0eXAiO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bW9jbyIsImlyY2Nsb3VkIiwib2t0YV9tZmEiLCJjbG91ZHNlcnZpY2VzX2RldiIsInZwbl9raW50bzFfc3RhZ2UiLCJ2cG5fa2ludG8xX3Byb2QiLCJlZ2VuY2lhX2RlIiwiYWN0aXZlX3NjbV9sZXZlbF8xIiwiYWxsX3NjbV9sZXZlbF8xIiwic2VydmljZV9zYWZhcmlib29rcyIsImV2ZXJ5b25lIl0sImh0dHBzOi8vc3NvLm1vemlsbGEuY29tL2NsYWltL1JFQURNRV9GSVJTVCI6IlBsZWFzZSByZWZlciB0byBodHRwczovL2dpdGh1Yi5jb20vbW96aWxsYS1pYW0vcGVyc29uLWFwaSBpbiBvcmRlciB0byBxdWVyeSBNb3ppbGxhIElBTSBDSVMgdXNlciBwcm9maWxlIGRhdGEifQ.EnF3oPHm90ZXnJ4egJqr-4eTaHMw-16beuZlvC66UsIehX7nBooP4VRfMW7KLwOHEnVVGV8jlxgn5p3Dnv1V_W6Yx4PLw7loeKrfhnEKw9onaH3frR_Vo0Y0-MgH4VnCbTwtGHsAfl32j2EoDljXYCqPhYCXD4H25o51lemAoKU3xWamF629FjooyhFTZPVI6JzKkOt39dQjALtXL9EVYRk0ameohHzOT0ZHA57H83FTrPmY_Jy5MWxv1aswcbzcENU1HsFEEkxkRCnGiosxYkStmDo957OQ0IXgNxdNe4VVXzuy5YiNmsjN-IF4tOADLFK5KnLHi4OBOGYiiRiJcQ")
|
||||
claims, err = validator.ExtractClaims(r)
|
||||
require.Nil(t, err)
|
||||
assert.Contains(t, claims.Email, "@mozilla.com")
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ const SERVICE_URL = 'http://localhost:8000'
|
|||
const AUTH0_CLIENT_ID = 'SLocf7Sa1ibd5GNJMMqO539g7cKvWBOI';
|
||||
const AUTH0_DOMAIN = 'auth.mozilla.auth0.com';
|
||||
const AUTH0_CALLBACK_URL = window.location.href;
|
||||
const SCOPES = 'openid profile';
|
||||
const SCOPES = 'openid profile email';
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', main);
|
||||
|
|
Загрузка…
Ссылка в новой задаче