| 1 |
package rp_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
|
| 7 |
"github.com/zitadel/oidc/v3/pkg/client/rp" |
| 8 |
"github.com/zitadel/oidc/v3/pkg/oidc" |
| 9 |
) |
| 10 |
|
| 11 |
type UserInfo struct { |
| 12 |
Subject string `json:"sub,omitempty"` |
| 13 |
oidc.UserInfoProfile |
| 14 |
oidc.UserInfoEmail |
| 15 |
oidc.UserInfoPhone |
| 16 |
Address *oidc.UserInfoAddress `json:"address,omitempty"` |
| 17 |
|
| 18 |
// Foo and Bar are custom claims |
| 19 |
Foo string `json:"foo,omitempty"` |
| 20 |
Bar struct { |
| 21 |
Val1 string `json:"val_1,omitempty"` |
| 22 |
Val2 string `json:"val_2,omitempty"` |
| 23 |
} `json:"bar,omitempty"` |
| 24 |
|
| 25 |
// Claims are all the combined claims, including custom. |
| 26 |
Claims map[string]any `json:"-,omitempty"` |
| 27 |
} |
| 28 |
|
| 29 |
func (u *UserInfo) GetSubject() string { |
| 30 |
return u.Subject |
| 31 |
} |
| 32 |
|
| 33 |
func ExampleUserinfo_custom() { |
| 34 |
rpo, err := rp.NewRelyingPartyOIDC(context.TODO(), "http://localhost:8080", "clientid", "clientsecret", "http://example.com/redirect", []string{oidc.ScopeOpenID, oidc.ScopeProfile, oidc.ScopeEmail, oidc.ScopePhone}) |
| 35 |
if err != nil { |
| 36 |
panic(err) |
| 37 |
} |
| 38 |
|
| 39 |
info, err := rp.Userinfo[*UserInfo](context.TODO(), "accesstokenstring", "Bearer", "userid", rpo) |
| 40 |
if err != nil { |
| 41 |
panic(err) |
| 42 |
} |
| 43 |
|
| 44 |
fmt.Println(info) |
| 45 |
} |