This repository has been archived by the owner on Apr 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dynamic OIDC configuration
- Loading branch information
Showing
11 changed files
with
451 additions
and
121 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 Tetrate | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package oidc | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// WellKnownConfig represents the OIDC well-known configuration | ||
type WellKnownConfig struct { | ||
Issuer string `json:"issuer"` | ||
AuthorizationEndpoint string `json:"authorization_endpoint"` | ||
TokenEndpoint string `json:"token_endpoint"` | ||
JWKSURL string `json:"jwks_uri"` | ||
ResponseTypesSupported []string `json:"response_types_supported"` | ||
SubjectTypesSupported []string `json:"subject_types_supported"` | ||
IDTokenSigningAlgorithms []string `json:"id_token_signing_alg_values_supported"` | ||
TokenEndpointAuthMethods []string `json:"token_endpoint_auth_methods_supported"` | ||
UserInfoEndpoint string `json:"userinfo_endpoint"` | ||
EndSessionEndpoint string `json:"end_session_endpoint"` | ||
RevocationEndpoint string `json:"revocation_endpoint"` | ||
IntrospectionEndpoint string `json:"introspection_endpoint"` | ||
ScopesSupported []string `json:"scopes_supported"` | ||
ClaimsSupported []string `json:"claims_supported"` | ||
CodeChallengeMethods []string `json:"code_challenge_methods_supported"` | ||
TokenRevocationEndpoint string `json:"token_revocation_endpoint"` | ||
} | ||
|
||
// GetWellKnownConfig retrieves the OIDC well-known configuration from the given issuer URL. | ||
func GetWellKnownConfig(client *http.Client, url string) (WellKnownConfig, error) { | ||
// Make a GET request to the well-known configuration endpoint | ||
response, err := client.Get(url) | ||
if err != nil { | ||
return WellKnownConfig{}, err | ||
} | ||
defer func() { _ = response.Body.Close() }() | ||
|
||
// Check if the response status code is successful | ||
if response.StatusCode != http.StatusOK { | ||
return WellKnownConfig{}, fmt.Errorf("failed to retrieve OIDC config: %s", response.Status) | ||
} | ||
|
||
// Decode the JSON response into the OIDCConfig struct | ||
var cfg WellKnownConfig | ||
if err = json.NewDecoder(response.Body).Decode(&cfg); err != nil { | ||
return WellKnownConfig{}, err | ||
} | ||
|
||
return cfg, nil | ||
} |
Oops, something went wrong.