mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-17 05:18:04 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
37 lines
753 B
Go
37 lines
753 B
Go
package actions
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/zitadel/oidc/v2/pkg/oidc"
|
|
)
|
|
|
|
type Context map[string]interface{}
|
|
|
|
func (c Context) set(name string, value interface{}) {
|
|
map[string]interface{}(c)[name] = value
|
|
}
|
|
|
|
func (c *Context) SetToken(t *oidc.Tokens) *Context {
|
|
if t == nil {
|
|
return c
|
|
}
|
|
if t.Token != nil && t.Token.AccessToken != "" {
|
|
c.set("accessToken", t.AccessToken)
|
|
}
|
|
if t.IDToken != "" {
|
|
c.set("idToken", t.IDToken)
|
|
}
|
|
if t.IDTokenClaims != nil {
|
|
c.set("getClaim", func(claim string) interface{} { return t.IDTokenClaims.GetClaim(claim) })
|
|
c.set("claimsJSON", func() (string, error) {
|
|
c, err := json.Marshal(t.IDTokenClaims)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(c), nil
|
|
})
|
|
}
|
|
return c
|
|
}
|