Skip to content

Commit e88aa00

Browse files
authored
Remove deprecated RedirectURLHostname (#313)
1 parent 601a319 commit e88aa00

File tree

3 files changed

+1
-79
lines changed

3 files changed

+1
-79
lines changed

e2e_test/e2e_test.go

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -89,77 +89,6 @@ func TestHappyPath(t *testing.T) {
8989
wg.Wait()
9090
}
9191

92-
func TestRedirectURLHostname(t *testing.T) {
93-
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
94-
defer cancel()
95-
openBrowserCh := make(chan string)
96-
var wg sync.WaitGroup
97-
wg.Add(1)
98-
go func() {
99-
defer wg.Done()
100-
defer close(openBrowserCh)
101-
// Start a local server and get a token.
102-
testServer := httptest.NewServer(&authserver.Handler{
103-
TestingT: t,
104-
NewAuthorizationResponse: func(req authserver.AuthorizationRequest) string {
105-
if want := "email profile"; req.Scope != want {
106-
t.Errorf("scope wants %s but %s", want, req.Scope)
107-
return fmt.Sprintf("%s?error=invalid_scope", req.RedirectURI)
108-
}
109-
if !assertRedirectURI(t, req.RedirectURI, "http", "127.0.0.1", "") {
110-
return fmt.Sprintf("%s?error=invalid_redirect_uri", req.RedirectURI)
111-
}
112-
return fmt.Sprintf("%s?state=%s&code=%s", req.RedirectURI, req.State, "AUTH_CODE")
113-
},
114-
NewTokenResponse: func(req authserver.TokenRequest) (int, string) {
115-
if want := "AUTH_CODE"; req.Code != want {
116-
t.Errorf("code wants %s but %s", want, req.Code)
117-
return 400, invalidGrantResponse
118-
}
119-
return 200, validTokenResponse
120-
},
121-
})
122-
defer testServer.Close()
123-
cfg := oauth2cli.Config{
124-
OAuth2Config: oauth2.Config{
125-
ClientID: "YOUR_CLIENT_ID",
126-
ClientSecret: "YOUR_CLIENT_SECRET",
127-
Scopes: []string{"email", "profile"},
128-
Endpoint: oauth2.Endpoint{
129-
AuthURL: testServer.URL + "/auth",
130-
TokenURL: testServer.URL + "/token",
131-
},
132-
},
133-
RedirectURLHostname: "127.0.0.1",
134-
LocalServerReadyChan: openBrowserCh,
135-
LocalServerMiddleware: loggingMiddleware(t),
136-
Logf: t.Logf,
137-
}
138-
token, err := oauth2cli.GetToken(ctx, cfg)
139-
if err != nil {
140-
t.Errorf("could not get a token: %s", err)
141-
return
142-
}
143-
if token.AccessToken != "ACCESS_TOKEN" {
144-
t.Errorf("AccessToken wants %s but %s", "ACCESS_TOKEN", token.AccessToken)
145-
}
146-
if token.RefreshToken != "REFRESH_TOKEN" {
147-
t.Errorf("RefreshToken wants %s but %s", "REFRESH_TOKEN", token.RefreshToken)
148-
}
149-
}()
150-
wg.Add(1)
151-
go func() {
152-
defer wg.Done()
153-
toURL, ok := <-openBrowserCh
154-
if !ok {
155-
t.Errorf("server already closed")
156-
return
157-
}
158-
client.GetAndVerify(t, toURL, 200, oauth2cli.DefaultLocalServerSuccessHTML)
159-
}()
160-
wg.Wait()
161-
}
162-
16392
func TestSuccessRedirect(t *testing.T) {
16493
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
16594
defer cancel()

oauth2cli.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ type Config struct {
6666
// Default to a string of random 32 bytes.
6767
State string
6868

69-
// DEPRECATED: Set OAuth2Config.RedirectURL instead.
70-
RedirectURLHostname string
71-
7269
// Candidates of hostname and port which the local server binds to.
7370
// You can set port number to 0 to allocate a free port.
7471
// If multiple addresses are given, it will try the ports in order.

server.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ func receiveCodeViaLocalServer(ctx context.Context, cfg *Config) (string, error)
2626

2727
if cfg.OAuth2Config.RedirectURL == "" {
2828
var localServerURL url.URL
29-
localServerHostname := "localhost"
30-
if cfg.RedirectURLHostname != "" {
31-
localServerHostname = cfg.RedirectURLHostname
32-
}
33-
localServerURL.Host = fmt.Sprintf("%s:%d", localServerHostname, localServerListener.Addr().(*net.TCPAddr).Port)
29+
localServerURL.Host = fmt.Sprintf("localhost:%d", localServerListener.Addr().(*net.TCPAddr).Port)
3430
localServerURL.Scheme = "http"
3531
if cfg.isLocalServerHTTPS() {
3632
localServerURL.Scheme = "https"

0 commit comments

Comments
 (0)