@@ -55,6 +55,7 @@ var CodeChallengeEncoder = base64.RawURLEncoding
5555
5656type ClientConfig struct {
5757 IssuerURL string
58+ RedirectURL string
5859 GrantType string
5960 ClientID string
6061 ClientSecret string
@@ -85,12 +86,12 @@ type ClientConfig struct {
8586 TLSRootCA string
8687}
8788
88- func RequestAuthorization (addr string , cconfig ClientConfig , sconfig ServerConfig , hc * http.Client ) (r Request , codeVerifier string , err error ) {
89+ func RequestAuthorization (cconfig ClientConfig , sconfig ServerConfig , hc * http.Client ) (r Request , codeVerifier string , err error ) {
8990 if r .URL , err = url .Parse (sconfig .AuthorizationEndpoint ); err != nil {
9091 return r , "" , errors .Wrapf (err , "failed to parse authorization endpoint" )
9192 }
9293
93- if codeVerifier , err = r .AuthorizeRequest (addr , cconfig , sconfig , hc ); err != nil {
94+ if codeVerifier , err = r .AuthorizeRequest (cconfig , sconfig , hc ); err != nil {
9495 return r , "" , errors .Wrapf (err , "failed to create authorization request" )
9596 }
9697
@@ -108,7 +109,6 @@ type PARResponse struct {
108109
109110func RequestPAR (
110111 ctx context.Context ,
111- addr string ,
112112 cconfig ClientConfig ,
113113 sconfig ServerConfig ,
114114 hc * http.Client ,
@@ -120,7 +120,7 @@ func RequestPAR(
120120 )
121121
122122 // push authorization request to /par
123- if codeVerifier , err = parRequest .AuthorizeRequest (addr , cconfig , sconfig , hc ); err != nil {
123+ if codeVerifier , err = parRequest .AuthorizeRequest (cconfig , sconfig , hc ); err != nil {
124124 return parRequest , parResponse , authorizeRequest , "" , errors .Wrapf (err , "failed to create authorization request" )
125125 }
126126
@@ -183,14 +183,19 @@ func RequestPAR(
183183 return parRequest , parResponse , authorizeRequest , codeVerifier , nil
184184}
185185
186- func WaitForCallback (clientConfig ClientConfig , serverConfig ServerConfig , addr string , hc * http.Client ) (request Request , err error ) {
186+ func WaitForCallback (clientConfig ClientConfig , serverConfig ServerConfig , hc * http.Client ) (request Request , err error ) {
187187 var (
188- srv = http.Server {Addr : addr }
188+ srv = http.Server {}
189+ redirectURL * url.URL
189190 signingKey jose.JSONWebKey
190191 encryptionKey jose.JSONWebKey
191192 done = make (chan struct {})
192193 )
193194
195+ if redirectURL , err = url .Parse (clientConfig .RedirectURL ); err != nil {
196+ return request , errors .Wrapf (err , "failed to parse redirect url: %s" , clientConfig .RedirectURL )
197+ }
198+
194199 if signingKey , err = ReadKey (SigningKey , serverConfig .JWKsURI , hc ); err != nil {
195200 return request , errors .Wrapf (err , "failed to read signing key from %s" , serverConfig .JWKsURI )
196201 }
@@ -201,7 +206,9 @@ func WaitForCallback(clientConfig ClientConfig, serverConfig ServerConfig, addr
201206 }
202207 }
203208
204- http .HandleFunc ("/callback" , func (w http.ResponseWriter , r * http.Request ) {
209+ srv .Addr = redirectURL .Host
210+
211+ http .HandleFunc (redirectURL .Path , func (w http.ResponseWriter , r * http.Request ) {
205212 defer func () {
206213 time .AfterFunc (time .Second , func () {
207214 if err := srv .Shutdown (context .Background ()); err != nil {
0 commit comments