From 779ad703c82458b14938296c653fbf1d8b93831e Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Wed, 16 Sep 2020 15:35:21 +0200 Subject: [PATCH] add NewJWTProfileAssertionFromKeyJSON --- pkg/oidc/token.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/pkg/oidc/token.go b/pkg/oidc/token.go index 2e4cf9c..1d49f26 100644 --- a/pkg/oidc/token.go +++ b/pkg/oidc/token.go @@ -2,6 +2,7 @@ package oidc import ( "encoding/json" + "io/ioutil" "strings" "time" @@ -60,14 +61,31 @@ type IDTokenClaims struct { } type JWTProfileAssertion struct { - PrivateKeyID string - PrivateKey []byte - Scopes []string - Issuer string - Subject string - Audience []string - Expiration time.Time - IssuedAt time.Time + PrivateKeyID string `json:"keyId"` + PrivateKey []byte `json:"key"` + Scopes []string `json:"-"` + Issuer string `json:"-"` + Subject string `json:"userId"` + Audience []string `json:"-"` + Expiration time.Time `json:"-"` + 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 {