Debian Codegraph @

pkg/oidc/authorization.go

raw
1 package oidc
2
3 import (
4 "log/slog"
5 )
6
7 const (
8 // ScopeOpenID defines the scope `openid`
9 // OpenID Connect requests MUST contain the `openid` scope value
10 ScopeOpenID = "openid"
11
12 // ScopeProfile defines the scope `profile`
13 // This (optional) scope value requests access to the End-User's default profile Claims,
14 // which are: name, family_name, given_name, middle_name, nickname, preferred_username,
15 // profile, picture, website, gender, birthdate, zoneinfo, locale, and updated_at.
16 ScopeProfile = "profile"
17
18 // ScopeEmail defines the scope `email`
19 // This (optional) scope value requests access to the email and email_verified Claims.
20 ScopeEmail = "email"
21
22 // ScopeAddress defines the scope `address`
23 // This (optional) scope value requests access to the address Claim.
24 ScopeAddress = "address"
25
26 // ScopePhone defines the scope `phone`
27 // This (optional) scope value requests access to the phone_number and phone_number_verified Claims.
28 ScopePhone = "phone"
29
30 // ScopeOfflineAccess defines the scope `offline_access`
31 // This (optional) scope value requests that an OAuth 2.0 Refresh Token be issued that can be used to obtain an Access Token
32 // that grants access to the End-User's UserInfo Endpoint even when the End-User is not present (not logged in).
33 ScopeOfflineAccess = "offline_access"
34
35 // ScopeBoundKey defines the scope `bound_key`
36 // This (optional) scope value requests an ID Token bound to a proof-of-possession key,
37 // as defined by OpenID Connect Key Binding 1.0.
38 //
39 // Experimental: OpenID Connect Key Binding 1.0 is a draft standard.
40 // This API may change or be removed without a major version bump.
41 ScopeBoundKey = "bound_key"
42
43 // ResponseTypeCode for the Authorization Code Flow returning a code from the Authorization Server
44 ResponseTypeCode ResponseType = "code"
45
46 // ResponseTypeIDToken for the Implicit Flow returning id and access tokens directly from the Authorization Server
47 ResponseTypeIDToken ResponseType = "id_token token"
48
49 // ResponseTypeIDTokenOnly for the Implicit Flow returning only id token directly from the Authorization Server
50 ResponseTypeIDTokenOnly ResponseType = "id_token"
51
52 DisplayPage Display = "page"
53 DisplayPopup Display = "popup"
54 DisplayTouch Display = "touch"
55 DisplayWAP Display = "wap"
56
57 ResponseModeQuery ResponseMode = "query"
58 ResponseModeFragment ResponseMode = "fragment"
59 ResponseModeFormPost ResponseMode = "form_post"
60
61 // PromptNone (`none`) disallows the Authorization Server to display any authentication or consent user interface pages.
62 // An error (login_required, interaction_required, ...) will be returned if the user is not already authenticated or consent is needed
63 PromptNone = "none"
64
65 // PromptLogin (`login`) directs the Authorization Server to prompt the End-User for reauthentication.
66 PromptLogin = "login"
67
68 // PromptConsent (`consent`) directs the Authorization Server to prompt the End-User for consent (of sharing information).
69 PromptConsent = "consent"
70
71 // PromptSelectAccount (`select_account `) directs the Authorization Server to prompt the End-User to select a user account (to enable multi user / session switching)
72 PromptSelectAccount = "select_account"
73 )
74
75 // AuthRequest according to:
76 // https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
77 type AuthRequest struct {
78 Scopes SpaceDelimitedArray `json:"scope" schema:"scope"`
79 ResponseType ResponseType `json:"response_type" schema:"response_type"`
80 ClientID string `json:"client_id" schema:"client_id"`
81 RedirectURI string `json:"redirect_uri" schema:"redirect_uri"`
82
83 State string `json:"state" schema:"state"`
84 Nonce string `json:"nonce" schema:"nonce"`
85
86 ResponseMode ResponseMode `json:"response_mode" schema:"response_mode"`
87 Display Display `json:"display" schema:"display"`
88 Prompt SpaceDelimitedArray `json:"prompt" schema:"prompt"`
89 MaxAge *uint `json:"max_age" schema:"max_age"`
90 UILocales Locales `json:"ui_locales" schema:"ui_locales"`
91 IDTokenHint string `json:"id_token_hint" schema:"id_token_hint"`
92 LoginHint string `json:"login_hint" schema:"login_hint"`
93 ACRValues SpaceDelimitedArray `json:"acr_values" schema:"acr_values"`
94
95 CodeChallenge string `json:"code_challenge" schema:"code_challenge"`
96 CodeChallengeMethod CodeChallengeMethod `json:"code_challenge_method" schema:"code_challenge_method"`
97
98 // RequestParam enables OIDC requests to be passed in a single, self-contained parameter (as JWT, called Request Object)
99 RequestParam string `schema:"request"`
100 }
101
102 func (a *AuthRequest) LogValue() slog.Value {
103 return slog.GroupValue(
104 slog.Any("scopes", a.Scopes),
105 slog.String("response_type", string(a.ResponseType)),
106 slog.String("client_id", a.ClientID),
107 slog.String("redirect_uri", a.RedirectURI),
108 )
109 }
110
111 // GetRedirectURI returns the redirect_uri value for the ErrAuthRequest interface
112 func (a *AuthRequest) GetRedirectURI() string {
113 return a.RedirectURI
114 }
115
116 // GetResponseType returns the response_type value for the ErrAuthRequest interface
117 func (a *AuthRequest) GetResponseType() ResponseType {
118 return a.ResponseType
119 }
120
121 // GetState returns the optional state value for the ErrAuthRequest interface
122 func (a *AuthRequest) GetState() string {
123 return a.State
124 }
125
126 // GetResponseMode returns the optional ResponseMode
127 func (a *AuthRequest) GetResponseMode() ResponseMode {
128 return a.ResponseMode
129 }