Skip to content

Commit

Permalink
fix: improve refresh webhook getter
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Aug 25, 2022
1 parent e1bb936 commit d40b1da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion driver/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ func (p *Provider) JWKSURL() *url.URL {
}

func (p *Provider) TokenRefreshHookURL() *url.URL {
return p.p.URIF(KeyRefreshTokenHookURL, nil)
if len(p.p.String(KeyRefreshTokenHookURL)) == 0 {
return nil
}

return p.p.RequestURIF(KeyRefreshTokenHookURL, nil)
}

func (p *Provider) AccessTokenStrategy() string {
Expand Down
13 changes: 13 additions & 0 deletions driver/config/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -382,3 +383,15 @@ func TestInfinitRefreshTokenTTL(t *testing.T) {

assert.Equal(t, -1*time.Nanosecond, c.RefreshTokenLifespan())
}

func TestTokenRefreshHookURL(t *testing.T) {
l := logrusx.New("", "")
l.Logrus().SetOutput(ioutil.Discard)
c := MustNew(context.Background(), l, configx.SkipValidation())

assert.EqualValues(t, (*url.URL)(nil), c.TokenRefreshHookURL())
c.MustSet(KeyRefreshTokenHookURL, "")
assert.EqualValues(t, (*url.URL)(nil), c.TokenRefreshHookURL())
c.MustSet(KeyRefreshTokenHookURL, "http://localhost:8080/oauth/token_refresh")
assert.EqualValues(t, "http://localhost:8080/oauth/token_refresh", c.TokenRefreshHookURL().String())
}
1 change: 1 addition & 0 deletions oauth2/oauth2_auth_code_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type clientCreator interface {
func TestAuthCodeWithDefaultStrategy(t *testing.T) {
reg := internal.NewMockedRegistry(t)
reg.Config().MustSet(config.KeyAccessTokenStrategy, "opaque")
reg.Config().MustSet(config.KeyRefreshTokenHookURL, "")
publicTS, adminTS := testhelpers.NewOAuth2Server(t, reg)

newOAuth2Client := func(t *testing.T, cb string) (*hc.Client, *oauth2.Config) {
Expand Down

0 comments on commit d40b1da

Please sign in to comment.