mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 03:27:02 -07:00
Changed RegisterOAuthClient to take audience string slice as arg
This commit is contained in:
parent
76992c296a
commit
c700020b04
3 changed files with 20 additions and 5 deletions
|
|
@ -208,8 +208,9 @@ func (client *Client) AddTrustedIssuer(remoteUrl string, idp *oidc.IdentityProvi
|
||||||
return io.ReadAll(res.Body)
|
return io.ReadAll(res.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) RegisterOAuthClient(registerUrl string, audience string) ([]byte, error) {
|
func (client *Client) RegisterOAuthClient(registerUrl string, audience []string) ([]byte, error) {
|
||||||
// hydra endpoint: POST /clients
|
// hydra endpoint: POST /clients
|
||||||
|
audience = util.QuoteArrayStrings(audience)
|
||||||
data := []byte(fmt.Sprintf(`{
|
data := []byte(fmt.Sprintf(`{
|
||||||
"client_name": "%s",
|
"client_name": "%s",
|
||||||
"client_secret": "%s",
|
"client_secret": "%s",
|
||||||
|
|
@ -217,8 +218,8 @@ func (client *Client) RegisterOAuthClient(registerUrl string, audience string) (
|
||||||
"scope": "openid email profile",
|
"scope": "openid email profile",
|
||||||
"grant_types": ["client_credentials", "urn:ietf:params:oauth:grant-type:jwt-bearer"],
|
"grant_types": ["client_credentials", "urn:ietf:params:oauth:grant-type:jwt-bearer"],
|
||||||
"response_types": ["token"],
|
"response_types": ["token"],
|
||||||
"audience": ["%s"]
|
"audience": [%s]
|
||||||
}`, client.Id, client.Secret, audience))
|
}`, client.Id, client.Secret, strings.Join(audience, ",")))
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", registerUrl, bytes.NewBuffer(data))
|
req, err := http.NewRequest("POST", registerUrl, bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -191,7 +192,7 @@ func Login(config *Config) error {
|
||||||
|
|
||||||
// extract the subject from ID token claims
|
// extract the subject from ID token claims
|
||||||
var subject string
|
var subject string
|
||||||
var audience string
|
var audience []string
|
||||||
var idJsonPayload map[string]any
|
var idJsonPayload map[string]any
|
||||||
var idJwtPayload []byte = idJwtSegments[1]
|
var idJwtPayload []byte = idJwtSegments[1]
|
||||||
if idJwtPayload != nil {
|
if idJwtPayload != nil {
|
||||||
|
|
@ -200,7 +201,13 @@ func Login(config *Config) error {
|
||||||
return fmt.Errorf("failed to unmarshal JWT: %v", err)
|
return fmt.Errorf("failed to unmarshal JWT: %v", err)
|
||||||
}
|
}
|
||||||
subject = idJsonPayload["sub"].(string)
|
subject = idJsonPayload["sub"].(string)
|
||||||
audience = idJsonPayload["aud"].(string)
|
audType := reflect.ValueOf(idJsonPayload["aud"])
|
||||||
|
switch audType.Kind() {
|
||||||
|
case reflect.String:
|
||||||
|
audience = append(audience, idJsonPayload["aud"].(string))
|
||||||
|
case reflect.Array:
|
||||||
|
audience = idJsonPayload["aud"].([]string)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("failed to extract subject from ID token claims")
|
return fmt.Errorf("failed to extract subject from ID token claims")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,3 +100,10 @@ func Tokenize(s string) map[string]any {
|
||||||
|
|
||||||
return tokens
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func QuoteArrayStrings(arr []string) []string {
|
||||||
|
for i, v := range arr {
|
||||||
|
arr[i] = "\"" + v + "\""
|
||||||
|
}
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue