@@ -50,32 +50,47 @@ type BrowserParams struct {
5050 Audience string
5151 LoginHandle string
5252 AllowSignup bool
53- // RequestRefreshToken opts this authorization into receiving an expiring access token along with
54- // a refresh token, by requesting the "offline_access" scope. Servers that do not support
55- // expiring tokens ignore it and issue a non-expiring token with no refresh token.
56- RequestRefreshToken bool
53+ }
54+
55+ // BrowserURLOption configures an authorization request.
56+ type BrowserURLOption func (* browserURLOptions )
57+
58+ type browserURLOptions struct {
59+ requestRefreshToken bool
60+ }
61+
62+ // WithRefreshToken requests an expiring access token and a refresh token. Servers that do not
63+ // support expiring tokens ignore this and issue a non-expiring token with no refresh token.
64+ func WithRefreshToken () BrowserURLOption {
65+ return func (options * browserURLOptions ) {
66+ options .requestRefreshToken = true
67+ }
5768}
5869
5970// BrowserURL appends GET query parameters to baseURL and returns the url that the user should
6071// navigate to in their web browser.
61- func (flow * Flow ) BrowserURL (baseURL string , params BrowserParams ) (string , error ) {
72+ func (flow * Flow ) BrowserURL (baseURL string , params BrowserParams , options ... BrowserURLOption ) (string , error ) {
6273 ru , err := url .Parse (params .RedirectURI )
6374 if err != nil {
6475 return "" , err
6576 }
6677
78+ requestOptions := browserURLOptions {}
79+ for _ , option := range options {
80+ option (& requestOptions )
81+ }
82+
6783 ru .Host = fmt .Sprintf ("%s:%d" , ru .Hostname (), flow .server .Port ())
6884 flow .server .CallbackPath = ru .Path
6985 flow .clientID = params .ClientID
7086
71- scopes := params .Scopes
72- if params .RequestRefreshToken {
73- scopes = api .AppendOfflineAccess (scopes )
74- }
75-
7687 q := url.Values {}
7788 q .Set ("client_id" , params .ClientID )
7889 q .Set ("redirect_uri" , ru .String ())
90+ scopes := params .Scopes
91+ if requestOptions .requestRefreshToken {
92+ scopes = api .AppendOfflineAccess (scopes )
93+ }
7994 q .Set ("scope" , strings .Join (scopes , " " ))
8095 q .Set ("state" , flow .state )
8196
0 commit comments