@@ -50,22 +50,23 @@ const DefaultLocalServerSuccessHTML = `
5050// Config represents a config for GetToken.
5151type Config struct {
5252 // OAuth2 config.
53- // RedirectURL will be automatically set to the local server.
53+ // If the RedirectURL field is not set, default to http://localhost with the allocated port and LocalServerCallbackPath.
54+ // If the RedirectURL field is set, make sure it matches the LocalServerBindAddress and LocalServerCallbackPath.
5455 OAuth2Config oauth2.Config
5556
5657 // Options for an authorization request.
5758 // You can set oauth2.AccessTypeOffline or oauth2.S256ChallengeOption.
5859 AuthCodeOptions []oauth2.AuthCodeOption
60+
5961 // Options for a token request.
6062 // You can set oauth2.VerifierOption.
6163 TokenRequestOptions []oauth2.AuthCodeOption
64+
6265 // State parameter in the authorization request.
6366 // Default to a string of random 32 bytes.
6467 State string
6568
66- // Hostname of the redirect URL.
67- // You can set this if your provider does not accept localhost.
68- // Default to localhost.
69+ // DEPRECATED: Set OAuth2Config.RedirectURL instead.
6970 RedirectURLHostname string
7071
7172 // Candidates of hostname and port which the local server binds to.
@@ -79,24 +80,31 @@ type Config struct {
7980 // certificates. It's recommended that the public key's SANs contain
8081 // the loopback addresses - 'localhost', '127.0.0.1' and '::1'
8182 LocalServerCertFile string
83+
8284 // A PEM-encoded private key for the certificate.
8385 // This is required when LocalServerCertFile is set.
8486 LocalServerKeyFile string
8587
8688 // Callback path of the local server.
87- // If your provider requires a specific path of the redirect URL, set it here.
89+ // If your provider requires a specific path of the redirect URL, set this field.
90+ // Default to none.
8891 LocalServerCallbackPath string
8992
9093 // Response HTML body on authorization completed.
9194 // Default to DefaultLocalServerSuccessHTML.
9295 LocalServerSuccessHTML string
93- // Middleware for the local server. Default to none.
96+
97+ // Middleware for the local server.
98+ // Default to none.
9499 LocalServerMiddleware func (h http.Handler ) http.Handler
95- // A channel to send its URL when the local server is ready. Default to none.
100+
101+ // A channel to send the local server URL when it is ready.
102+ // Default to none.
96103 LocalServerReadyChan chan <- string
97104
98105 // Redirect URL upon successful login
99106 SuccessRedirectURL string
107+
100108 // Redirect URL upon failed login
101109 FailureRedirectURL string
102110
@@ -113,9 +121,6 @@ func (cfg *Config) validateAndSetDefaults() error {
113121 (cfg .LocalServerCertFile == "" && cfg .LocalServerKeyFile != "" ) {
114122 return fmt .Errorf ("both LocalServerCertFile and LocalServerKeyFile must be set" )
115123 }
116- if cfg .RedirectURLHostname == "" {
117- cfg .RedirectURLHostname = "localhost"
118- }
119124 if cfg .State == "" {
120125 state , err := oauth2params .NewState ()
121126 if err != nil {
0 commit comments