Debian Codegraph @

internal/oauth2/openvpn_auth_oauth2/context.go

raw
1 // Package openvpn_auth_oauth2 defines the native Go values exposed to CEL expressions.
2 package openvpn_auth_oauth2
3
4 import (
5 celtypes "cel.dev/cel-go/common/types"
6 "cel.dev/cel-go/common/types/ref"
7 "cel.dev/cel-go/common/types/traits"
8 )
9
10 // AuthContext contains authentication-specific CEL values.
11 type AuthContext struct {
12 Mode *string `cel:"mode"`
13 }
14
15 // OpenVPNContext contains OpenVPN session-specific CEL values.
16 type OpenVPNContext struct {
17 CommonName *string `cel:"commonName"`
18 IP *string `cel:"ip"`
19 SessionState *string `cel:"sessionState"`
20 }
21
22 // TokenContext contains OAuth2 token-specific CEL values.
23 type TokenContext struct {
24 Claims Claims `cel:"claims"`
25 IP *string `cel:"ip"`
26 }
27
28 // Claims adapts dynamic token claims through CEL-Go's native map implementation.
29 // NativeTypes does not infer map[string]any as map<string, dyn> directly.
30 type Claims struct {
31 traits.Mapper
32 }
33
34 // NewClaims adapts token claims to CEL's map<string, dyn> value.
35 func NewClaims(claims map[string]any) Claims {
36 return Claims{
37 Mapper: celtypes.NewStringInterfaceMap(celtypes.DefaultTypeAdapter, claims),
38 }
39 }
40
41 // Type reports the map type to NativeTypes while the embedded mapper implements
42 // the remaining CEL map operations.
43 func (Claims) Type() ref.Type {
44 return celtypes.NewMapType(celtypes.StringType, celtypes.DynType)
45 }
46
47 // UserContext contains normalized user-specific CEL values.
48 type UserContext struct {
49 Email *string `cel:"email"`
50 Subject *string `cel:"subject"`
51 Username *string `cel:"username"`
52 Groups []string `cel:"groups"`
53 Roles []string `cel:"roles"`
54 }