use claims map instead of struct
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
@@ -98,16 +98,22 @@ func NewStaticSelector(cfg *config.StaticSelectorConf) Selector {
|
||||
func NewMigrationSelector(cfg *config.MigrationSelectorConf, ss accounts.AccountsService) Selector {
|
||||
var acc = ss
|
||||
return func(ctx context.Context, r *http.Request) (s string, err error) {
|
||||
var userID string
|
||||
if claims := oidc.FromContext(r.Context()); claims != nil {
|
||||
userID = claims.PreferredUsername
|
||||
if _, err := acc.GetAccount(ctx, &accounts.GetAccountRequest{Id: userID}); err != nil {
|
||||
return cfg.AccNotFoundPolicy, nil
|
||||
}
|
||||
|
||||
return cfg.AccFoundPolicy, nil
|
||||
var claims map[string]interface{}
|
||||
if claims = oidc.FromContext(r.Context()); claims == nil {
|
||||
return cfg.UnauthenticatedPolicy, nil
|
||||
}
|
||||
|
||||
return cfg.UnauthenticatedPolicy, nil
|
||||
var userID string
|
||||
var ok bool
|
||||
if userID, ok = claims[oidc.PreferredUsername].(string); !ok {
|
||||
// TODO clarify: what if the user just has no username ...
|
||||
return cfg.AccNotFoundPolicy, nil
|
||||
}
|
||||
|
||||
if _, err := acc.GetAccount(ctx, &accounts.GetAccountRequest{Id: userID}); err != nil {
|
||||
return cfg.AccNotFoundPolicy, nil
|
||||
}
|
||||
return cfg.AccFoundPolicy, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func TestStaticSelector(t *testing.T) {
|
||||
|
||||
type testCase struct {
|
||||
AccSvcShouldReturnError bool
|
||||
Claims *oidc.StandardClaims
|
||||
Claims map[string]interface{}
|
||||
Expected string
|
||||
}
|
||||
|
||||
@@ -80,8 +80,9 @@ func TestMigrationSelector(t *testing.T) {
|
||||
UnauthenticatedPolicy: "unauth",
|
||||
}
|
||||
var tests = []testCase{
|
||||
{true, &oidc.StandardClaims{PreferredUsername: "Hans"}, "not_found"},
|
||||
{false, &oidc.StandardClaims{PreferredUsername: "Hans"}, "found"},
|
||||
{true, map[string]interface{}{oidc.PreferredUsername: "Hans"}, "not_found"},
|
||||
{true, map[string]interface{}{oidc.Email: "hans@example.test"}, "not_found"},
|
||||
{false, map[string]interface{}{oidc.PreferredUsername: "Hans"}, "found"},
|
||||
{false, nil, "unauth"},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user