use keycloak_realm properly for keycloak user lookups (#14401)

In case a user-defined a value for the MINIO_IDENTITY_OPENID_KEYCLOAK_REALM 
environment variable, construct the path properly.
This commit is contained in:
hellivan 2022-02-24 19:16:53 +01:00 committed by GitHub
parent 2cea944cdb
commit 5307e18085
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"path"
"strings" "strings"
"sync" "sync"
) )
@ -83,11 +84,12 @@ func (k *KeycloakProvider) LoginWithClientID(clientID, clientSecret string) erro
// LookupUser lookup user by their userid. // LookupUser lookup user by their userid.
func (k *KeycloakProvider) LookupUser(userid string) (User, error) { func (k *KeycloakProvider) LookupUser(userid string) (User, error) {
lookupUserID := k.adminURL + "/realms" + k.realm + "/users/" + userid req, err := http.NewRequest(http.MethodGet, k.adminURL, nil)
req, err := http.NewRequest(http.MethodGet, lookupUserID, nil)
if err != nil { if err != nil {
return User{}, err return User{}, err
} }
req.URL.Path = path.Join(req.URL.Path, "realms", k.realm, "users", userid)
k.Lock() k.Lock()
accessToken := k.accessToken accessToken := k.accessToken
k.Unlock() k.Unlock()