add NewJWTProfileAssertionFromKeyJSON
This commit is contained in:
parent
0547bfbc1e
commit
779ad703c8
1 changed files with 26 additions and 8 deletions
|
@ -2,6 +2,7 @@ package oidc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -60,14 +61,31 @@ type IDTokenClaims struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type JWTProfileAssertion struct {
|
type JWTProfileAssertion struct {
|
||||||
PrivateKeyID string
|
PrivateKeyID string `json:"keyId"`
|
||||||
PrivateKey []byte
|
PrivateKey []byte `json:"key"`
|
||||||
Scopes []string
|
Scopes []string `json:"-"`
|
||||||
Issuer string
|
Issuer string `json:"-"`
|
||||||
Subject string
|
Subject string `json:"userId"`
|
||||||
Audience []string
|
Audience []string `json:"-"`
|
||||||
Expiration time.Time
|
Expiration time.Time `json:"-"`
|
||||||
IssuedAt time.Time
|
IssuedAt time.Time `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJWTProfileAssertionFromKeyJSON(filename string, audience []string) (*JWTProfileAssertion, error) {
|
||||||
|
data, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
keyData := new(struct {
|
||||||
|
KeyID string `json:"keyId"`
|
||||||
|
Key []byte `json:"key"`
|
||||||
|
UserID string `json:"userId"`
|
||||||
|
})
|
||||||
|
err = json.Unmarshal(data, keyData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewJWTProfileAssertion(keyData.UserID, keyData.KeyID, audience, keyData.Key), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJWTProfileAssertion(userID, keyID string, audience []string, key []byte) *JWTProfileAssertion {
|
func NewJWTProfileAssertion(userID, keyID string, audience []string, key []byte) *JWTProfileAssertion {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue