Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
538a6c8ae6 |
No files matched your search
@@ -70,6 +70,9 @@ type User struct {
|
|||||||
Locale string `json:"locale"`
|
Locale string `json:"locale"`
|
||||||
TimeZone string `json:"time_zone"`
|
TimeZone string `json:"time_zone"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
|
// Attributes are the user's attributes by name (department,
|
||||||
|
// cost_center, ...); none with a yaiam before them.
|
||||||
|
Attributes map[string]string `json:"attributes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Users lists the tenant's users.
|
// Users lists the tenant's users.
|
||||||
|
|||||||
+2
-2
@@ -57,7 +57,7 @@ func newAdminFake(t *testing.T) *adminFake {
|
|||||||
case "users":
|
case "users":
|
||||||
fmt.Fprint(w, `{"items":[{"id":"u-1","ref":"alice","username":"alice","display_name":"Alice","user_state":"active","home":true}]}`)
|
fmt.Fprint(w, `{"items":[{"id":"u-1","ref":"alice","username":"alice","display_name":"Alice","user_state":"active","home":true}]}`)
|
||||||
case "users/alice":
|
case "users/alice":
|
||||||
fmt.Fprint(w, `{"id":"u-1","username":"alice","display_name":"Alice","email":"alice@example.org","email_verified":true,"state":"active"}`)
|
fmt.Fprint(w, `{"id":"u-1","username":"alice","display_name":"Alice","email":"alice@example.org","email_verified":true,"state":"active","attributes":{"department":"IT"}}`)
|
||||||
case "groups":
|
case "groups":
|
||||||
fmt.Fprint(w, `{"items":[{"id":"g-1","name":"staff","protected":false}]}`)
|
fmt.Fprint(w, `{"items":[{"id":"g-1","name":"staff","protected":false}]}`)
|
||||||
case "groups/staff/members":
|
case "groups/staff/members":
|
||||||
@@ -88,7 +88,7 @@ func TestAdmin(t *testing.T) {
|
|||||||
t.Fatalf("users %+v, %v", users, err)
|
t.Fatalf("users %+v, %v", users, err)
|
||||||
}
|
}
|
||||||
u, err := a.User(ctx, "alice")
|
u, err := a.User(ctx, "alice")
|
||||||
if err != nil || u.Email != "alice@example.org" || !u.EmailVerified {
|
if err != nil || u.Email != "alice@example.org" || !u.EmailVerified || u.Attributes["department"] != "IT" {
|
||||||
t.Errorf("user %+v, %v", u, err)
|
t.Errorf("user %+v, %v", u, err)
|
||||||
}
|
}
|
||||||
groups, err := a.Groups(ctx)
|
groups, err := a.Groups(ctx)
|
||||||
|
|||||||
+13
-6
@@ -31,9 +31,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// WebScopes are asked for when Web.Scopes is nil: who the user is, their
|
// WebScopes are asked for when Web.Scopes is nil: who the user is, their
|
||||||
// address, and their groups and roles at yaiam (the client must be
|
// address, their groups and roles at yaiam (the client must be allowed
|
||||||
// allowed "groups" and "roles").
|
// "groups" and "roles") and the user attributes released to the client
|
||||||
var WebScopes = []string{"openid", "profile", "email", "groups", "roles"}
|
// (yaiam allows "attributes" once some are). A scope the client is not
|
||||||
|
// allowed is left out, not refused.
|
||||||
|
var WebScopes = []string{"openid", "profile", "email", "groups", "roles", "attributes"}
|
||||||
|
|
||||||
// signInLifetime is how long a started sign-in may take.
|
// signInLifetime is how long a started sign-in may take.
|
||||||
const signInLifetime = 10 * time.Minute
|
const signInLifetime = 10 * time.Minute
|
||||||
@@ -88,6 +90,9 @@ type SignedIn struct {
|
|||||||
// Groups and Roles with the scopes groups and roles: the names of the
|
// Groups and Roles with the scopes groups and roles: the names of the
|
||||||
// user's groups (subgroups' members included) and roles in the tenant.
|
// user's groups (subgroups' members included) and roles in the tenant.
|
||||||
Groups, Roles []string
|
Groups, Roles []string
|
||||||
|
// Attributes with the scope attributes: the user's attributes yaiam
|
||||||
|
// releases to the client (department, cost_center, ...), by name.
|
||||||
|
Attributes map[string]string
|
||||||
// ACR is how strongly the user signed in ("pwd", "mfa", "phr"), AMR
|
// ACR is how strongly the user signed in ("pwd", "mfa", "phr"), AMR
|
||||||
// with what; AuthTime when.
|
// with what; AuthTime when.
|
||||||
ACR string
|
ACR string
|
||||||
@@ -282,6 +287,7 @@ func (w *Web) Callback(ctx context.Context, rw http.ResponseWriter, r *http.Requ
|
|||||||
return nil, errors.New("yaiam: UserInfo names another user than the ID token")
|
return nil, errors.New("yaiam: UserInfo names another user than the ID token")
|
||||||
}
|
}
|
||||||
out.Username, out.Name, out.Email, out.EmailVerified, out.Groups, out.Roles = u.Username, u.Name, u.Email, u.EmailVerified, u.Groups, u.Roles
|
out.Username, out.Name, out.Email, out.EmailVerified, out.Groups, out.Roles = u.Username, u.Name, u.Email, u.EmailVerified, u.Groups, u.Roles
|
||||||
|
out.Attributes = u.Attributes
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
@@ -389,9 +395,10 @@ func (w *Web) checkIDToken(idToken, nonce string) (*idClaims, error) {
|
|||||||
// webUserInfo is UserInfo's answer with what a web sign-in also takes.
|
// webUserInfo is UserInfo's answer with what a web sign-in also takes.
|
||||||
type webUserInfo struct {
|
type webUserInfo struct {
|
||||||
UserInfo
|
UserInfo
|
||||||
EmailVerified bool `json:"email_verified"`
|
EmailVerified bool `json:"email_verified"`
|
||||||
Groups []string `json:"groups"`
|
Groups []string `json:"groups"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
|
Attributes map[string]string `json:"attributes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Web) userInfo(ctx context.Context, m *metadata, t *Token) (*webUserInfo, error) {
|
func (w *Web) userInfo(ctx context.Context, m *metadata, t *Token) (*webUserInfo, error) {
|
||||||
|
|||||||
+3
-3
@@ -71,7 +71,7 @@ func newOP(t *testing.T) *op {
|
|||||||
o.ts = httptest.NewServer(mux)
|
o.ts = httptest.NewServer(mux)
|
||||||
t.Cleanup(o.ts.Close)
|
t.Cleanup(o.ts.Close)
|
||||||
o.issuer = o.ts.URL + "/t/default"
|
o.issuer = o.ts.URL + "/t/default"
|
||||||
o.userBody = `{"sub":"u-1","preferred_username":"alice","name":"Alice","email":"alice@example.org","email_verified":true,"groups":["staff","dev"],"roles":["editor"]}`
|
o.userBody = `{"sub":"u-1","preferred_username":"alice","name":"Alice","email":"alice@example.org","email_verified":true,"groups":["staff","dev"],"roles":["editor"],"attributes":{"department":"IT"}}`
|
||||||
o.claims = func(nonce string) map[string]any {
|
o.claims = func(nonce string) map[string]any {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
return map[string]any{"iss": o.issuer, "sub": "u-1", "aud": "web", "exp": now.Add(5 * time.Minute).Unix(), "iat": now.Unix(),
|
return map[string]any{"iss": o.issuer, "sub": "u-1", "aud": "web", "exp": now.Add(5 * time.Minute).Unix(), "iat": now.Unix(),
|
||||||
@@ -137,7 +137,7 @@ func TestWebSignIn(t *testing.T) {
|
|||||||
w := o.web()
|
w := o.web()
|
||||||
q, cookie := o.start(t, w, "/staff?x=1")
|
q, cookie := o.start(t, w, "/staff?x=1")
|
||||||
if q.Get("response_type") != "code" || q.Get("client_id") != "web" || q.Get("redirect_uri") != w.RedirectURL ||
|
if q.Get("response_type") != "code" || q.Get("client_id") != "web" || q.Get("redirect_uri") != w.RedirectURL ||
|
||||||
q.Get("scope") != "openid profile email groups roles" || q.Get("code_challenge_method") != "S256" || q.Get("state") == "" || q.Get("nonce") == "" {
|
q.Get("scope") != "openid profile email groups roles attributes" || q.Get("code_challenge_method") != "S256" || q.Get("state") == "" || q.Get("nonce") == "" {
|
||||||
t.Errorf("authorization request %v", q)
|
t.Errorf("authorization request %v", q)
|
||||||
}
|
}
|
||||||
if !cookie.HttpOnly || cookie.SameSite != http.SameSiteLaxMode || cookie.Name != "yaiam_signin" || cookie.Secure || cookie.MaxAge != 600 {
|
if !cookie.HttpOnly || cookie.SameSite != http.SameSiteLaxMode || cookie.Name != "yaiam_signin" || cookie.Secure || cookie.MaxAge != 600 {
|
||||||
@@ -148,7 +148,7 @@ func TestWebSignIn(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if s.Subject != "u-1" || s.Username != "alice" || s.Name != "Alice" || s.Email != "alice@example.org" || !s.EmailVerified ||
|
if s.Subject != "u-1" || s.Username != "alice" || s.Name != "Alice" || s.Email != "alice@example.org" || !s.EmailVerified ||
|
||||||
strings.Join(s.Groups, ",") != "staff,dev" || strings.Join(s.Roles, ",") != "editor" || s.ACR != "mfa" || s.AuthTime.IsZero() ||
|
strings.Join(s.Groups, ",") != "staff,dev" || strings.Join(s.Roles, ",") != "editor" || s.Attributes["department"] != "IT" || len(s.Attributes) != 1 || s.ACR != "mfa" || s.AuthTime.IsZero() ||
|
||||||
s.ReturnTo != "/staff?x=1" || s.Token.AccessToken != "at-1" || s.IDToken == "" {
|
s.ReturnTo != "/staff?x=1" || s.Token.AccessToken != "at-1" || s.IDToken == "" {
|
||||||
t.Errorf("signed in %+v", s)
|
t.Errorf("signed in %+v", s)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user