-
Notifications
You must be signed in to change notification settings - Fork 28
/
client_like.go
50 lines (44 loc) · 1.24 KB
/
client_like.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package oauth
import (
"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/lib/session"
"github.com/authgear/authgear-server/pkg/lib/session/idpsession"
)
type ClientLike struct {
IsFirstParty bool
PIIAllowedInIDToken bool
Scopes []string
}
var ClientLikeNotFound = &ClientLike{
IsFirstParty: false,
PIIAllowedInIDToken: false,
}
type OAuthClientResolver interface {
ResolveClient(clientID string) *config.OAuthClientConfig
}
func SessionClientLike(s session.Session, clientResolver OAuthClientResolver) *ClientLike {
scopes := SessionScopes(s)
switch s := s.(type) {
case *idpsession.IDPSession:
return &ClientLike{
IsFirstParty: true,
PIIAllowedInIDToken: false,
Scopes: scopes,
}
case *OfflineGrant:
client := clientResolver.ResolveClient(s.ClientID)
if client == nil {
return ClientLikeNotFound
}
return ClientClientLike(client, scopes)
default:
panic("oauth: unexpected session type")
}
}
func ClientClientLike(client *config.OAuthClientConfig, scopes []string) *ClientLike {
return &ClientLike{
IsFirstParty: client.IsFirstParty(),
PIIAllowedInIDToken: client.PIIAllowedInIDToken(),
Scopes: scopes,
}
}