@@ -17,10 +17,32 @@ type httpClient interface {
1717 PostForm (string , url.Values ) (* http.Response , error )
1818}
1919
20+ // Host defines the endpoints used to authorize against an OAuth server.
21+ type Host struct {
22+ DeviceCodeURL string
23+ AuthorizeURL string
24+ TokenURL string
25+ }
26+
27+ // GitHubHost constructs a Host from the given URL to a GitHub instance.
28+ func GitHubHost (hostURL string ) * Host {
29+ u , _ := url .Parse (hostURL )
30+
31+ return & Host {
32+ DeviceCodeURL : fmt .Sprintf ("%s://%s/login/device/code" , u .Scheme , u .Host ),
33+ AuthorizeURL : fmt .Sprintf ("%s://%s/login/oauth/authorize" , u .Scheme , u .Host ),
34+ TokenURL : fmt .Sprintf ("%s://%s/login/oauth/access_token" , u .Scheme , u .Host ),
35+ }
36+ }
37+
2038// Flow facilitates a single OAuth authorization flow.
2139type Flow struct {
22- // The host to authorize the app with.
40+ // The hostname to authorize the app with.
41+ //
42+ // Deprecated: Use Host instead.
2343 Hostname string
44+ // Host configuration to authorize the app with.
45+ Host * Host
2446 // OAuth scopes to request from the user.
2547 Scopes []string
2648 // OAuth application ID.
@@ -47,18 +69,6 @@ type Flow struct {
4769 Stdout io.Writer
4870}
4971
50- func deviceInitURL (host string ) string {
51- return fmt .Sprintf ("https://%s/login/device/code" , host )
52- }
53-
54- func webappInitURL (host string ) string {
55- return fmt .Sprintf ("https://%s/login/oauth/authorize" , host )
56- }
57-
58- func tokenURL (host string ) string {
59- return fmt .Sprintf ("https://%s/login/oauth/access_token" , host )
60- }
61-
6272// DetectFlow tries to perform Device flow first and falls back to Web application flow.
6373func (oa * Flow ) DetectFlow () (* api.AccessToken , error ) {
6474 accessToken , err := oa .DeviceFlow ()
0 commit comments