Skip to content

Commit 18be49c

Browse files
committed
Add Endpoint() api call to oidc.Provider
1 parent b85f9a7 commit 18be49c

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

oidc/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,9 @@ func unmarshalRespJSON(r *http.Response, body []byte, v interface{}) error {
826826
}
827827
return fmt.Errorf("%s: expected Content-Type = application/json, got %q and could not unmarshal it as JSON: %w", op, ct, err)
828828
}
829+
830+
// Endpoint returns the oauth2 Endpoint information that the go-oidc
831+
// provider already knows about from its probe of the Discovery URL
832+
func (p *Provider) Endpoint() oauth2.Endpoint {
833+
return p.provider.Endpoint()
834+
}

oidc/provider_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,3 +1731,15 @@ func TestProvider_DiscoveryInfo(t *testing.T) {
17311731
})
17321732
}
17331733
}
1734+
1735+
func TestProvider_Endpoint(t *testing.T) {
1736+
t.Parallel()
1737+
tp := StartTestProvider(t)
1738+
p := testNewProvider(t, "client-id", "client-secret", "redirect", tp)
1739+
1740+
endpoint := p.Endpoint()
1741+
assert := assert.New(t)
1742+
assert.NotEqual(endpoint.AuthURL, "")
1743+
assert.NotEqual(endpoint.DeviceAuthURL, "")
1744+
assert.NotEqual(endpoint.TokenURL, "")
1745+
}

oidc/testing_provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ func (p *TestProvider) ServeHTTP(w http.ResponseWriter, req *http.Request) {
11301130
const (
11311131
openidConfiguration = "/.well-known/openid-configuration"
11321132
authorize = "/authorize"
1133+
deviceAuthorize = "/deviceauthorize"
11331134
token = "/token"
11341135
userInfo = "/userinfo"
11351136
wellKnownJwks = "/.well-known/jwks.json"
@@ -1160,6 +1161,7 @@ func (p *TestProvider) ServeHTTP(w http.ResponseWriter, req *http.Request) {
11601161
reply := struct {
11611162
Issuer string `json:"issuer"`
11621163
AuthEndpoint string `json:"authorization_endpoint"`
1164+
DeviceAuthEndpoint string `json:"device_authorization_endpoint"`
11631165
TokenEndpoint string `json:"token_endpoint"`
11641166
JWKSURI string `json:"jwks_uri"`
11651167
UserinfoEndpoint string `json:"userinfo_endpoint,omitempty"`
@@ -1170,6 +1172,7 @@ func (p *TestProvider) ServeHTTP(w http.ResponseWriter, req *http.Request) {
11701172
}{
11711173
Issuer: p.Addr(),
11721174
AuthEndpoint: p.Addr() + authorize,
1175+
DeviceAuthEndpoint: p.Addr() + deviceAuthorize,
11731176
TokenEndpoint: p.Addr() + token,
11741177
JWKSURI: p.Addr() + wellKnownJwks,
11751178
UserinfoEndpoint: p.Addr() + userInfo,

0 commit comments

Comments
 (0)