@@ -154,40 +154,65 @@ var supportedAlgorithms = map[string]bool{
154
154
EdDSA : true ,
155
155
}
156
156
157
- // ProviderConfig allows creating providers when discovery isn't supported. It's
158
- // generally easier to use NewProvider directly.
157
+ // ProviderConfig allows direct creation of a [Provider] from metadata
158
+ // configuration. This is intended for interop with providers that don't support
159
+ // discovery, or host the JSON discovery document at an off-spec path.
160
+ //
161
+ // The ProviderConfig struct specifies JSON struct tags to support document
162
+ // parsing.
163
+ //
164
+ // // Directly fetch the metadata document.
165
+ // resp, err := http.Get("https://login.example.com/custom-metadata-path")
166
+ // if err != nil {
167
+ // // ...
168
+ // }
169
+ // defer resp.Body.Close()
170
+ //
171
+ // // Parse config from JSON metadata.
172
+ // config := &oidc.ProviderConfig{}
173
+ // if err := json.NewDecoder(resp.Body).Decode(config); err != nil {
174
+ // // ...
175
+ // }
176
+ // p := config.NewProvider(context.Background())
177
+ //
178
+ // For providers that implement discovery, use [NewProvider] instead.
179
+ //
180
+ // See: https://openid.net/specs/openid-connect-discovery-1_0.html
159
181
type ProviderConfig struct {
160
182
// IssuerURL is the identity of the provider, and the string it uses to sign
161
183
// ID tokens with. For example "https://accounts.google.com". This value MUST
162
184
// match ID tokens exactly.
163
- IssuerURL string
185
+ IssuerURL string `json:"issuer"`
164
186
// AuthURL is the endpoint used by the provider to support the OAuth 2.0
165
187
// authorization endpoint.
166
- AuthURL string
188
+ AuthURL string `json:"authorization_endpoint"`
167
189
// TokenURL is the endpoint used by the provider to support the OAuth 2.0
168
190
// token endpoint.
169
- TokenURL string
191
+ TokenURL string `json:"token_endpoint"`
170
192
// DeviceAuthURL is the endpoint used by the provider to support the OAuth 2.0
171
193
// device authorization endpoint.
172
- DeviceAuthURL string
194
+ DeviceAuthURL string `json:"device_authorization_endpoint"`
173
195
// UserInfoURL is the endpoint used by the provider to support the OpenID
174
196
// Connect UserInfo flow.
175
197
//
176
198
// https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
177
- UserInfoURL string
199
+ UserInfoURL string `json:"userinfo_endpoint"`
178
200
// JWKSURL is the endpoint used by the provider to advertise public keys to
179
201
// verify issued ID tokens. This endpoint is polled as new keys are made
180
202
// available.
181
- JWKSURL string
203
+ JWKSURL string `json:"jwks_uri"`
182
204
183
205
// Algorithms, if provided, indicate a list of JWT algorithms allowed to sign
184
206
// ID tokens. If not provided, this defaults to the algorithms advertised by
185
207
// the JWK endpoint, then the set of algorithms supported by this package.
186
- Algorithms []string
208
+ Algorithms []string `json:"id_token_signing_alg_values_supported"`
187
209
}
188
210
189
211
// NewProvider initializes a provider from a set of endpoints, rather than
190
212
// through discovery.
213
+ //
214
+ // The provided context is only used for [http.Client] configuration through
215
+ // [ClientContext], not cancelation.
191
216
func (p * ProviderConfig ) NewProvider (ctx context.Context ) * Provider {
192
217
return & Provider {
193
218
issuer : p .IssuerURL ,
@@ -202,9 +227,14 @@ func (p *ProviderConfig) NewProvider(ctx context.Context) *Provider {
202
227
}
203
228
204
229
// NewProvider uses the OpenID Connect discovery mechanism to construct a Provider.
205
- //
206
230
// The issuer is the URL identifier for the service. For example: "https://accounts.google.com"
207
231
// or "https://login.salesforce.com".
232
+ //
233
+ // OpenID Connect providers that don't implement discovery or host the discovery
234
+ // document at a non-spec complaint path (such as requiring a URL parameter),
235
+ // should use [ProviderConfig] instead.
236
+ //
237
+ // See: https://openid.net/specs/openid-connect-discovery-1_0.html
208
238
func NewProvider (ctx context.Context , issuer string ) (* Provider , error ) {
209
239
wellKnown := strings .TrimSuffix (issuer , "/" ) + "/.well-known/openid-configuration"
210
240
req , err := http .NewRequest ("GET" , wellKnown , nil )
0 commit comments