|
1 | 1 | package oauth_test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "os" |
| 4 | + "fmt" |
| 5 | + "os" |
6 | 6 |
|
7 | | - "github.com/cli/oauth" |
| 7 | + "github.com/cli/oauth" |
8 | 8 | ) |
9 | 9 |
|
10 | 10 | // DetectFlow attempts to initiate OAuth Device flow with the server and falls back to OAuth Web |
11 | 11 | // application flow if Device flow seems unsupported. This approach isn't strictly needed for |
12 | 12 | // github.com, as its Device flow support is globally available, but it enables logging in to |
13 | 13 | // self-hosted GitHub instances as well. |
14 | 14 | func ExampleFlow_DetectFlow() { |
15 | | - host, err := oauth.NewGitHubHost("https://github.com") |
16 | | - if err != nil { |
17 | | - panic(err) |
18 | | - } |
19 | | - flow := &oauth.Flow{ |
20 | | - Host: host, |
21 | | - ClientID: os.Getenv("OAUTH_CLIENT_ID"), |
22 | | - ClientSecret: os.Getenv("OAUTH_CLIENT_SECRET"), // only applicable to web app flow |
23 | | - CallbackURI: "http://127.0.0.1/callback", // only applicable to web app flow |
24 | | - Scopes: []string{"repo", "read:org", "gist"}, |
25 | | - } |
| 15 | + host, err := oauth.NewGitHubHost("https://github.com") |
| 16 | + if err != nil { |
| 17 | + panic(err) |
| 18 | + } |
| 19 | + flow := &oauth.Flow{ |
| 20 | + Host: host, |
| 21 | + ClientID: os.Getenv("OAUTH_CLIENT_ID"), |
| 22 | + ClientSecret: os.Getenv("OAUTH_CLIENT_SECRET"), // only applicable to web app flow |
| 23 | + CallbackURI: "http://127.0.0.1/callback", // only applicable to web app flow |
| 24 | + Scopes: []string{"repo", "read:org", "gist"}, |
| 25 | + } |
26 | 26 |
|
27 | | - accessToken, err := flow.DetectFlow() |
28 | | - if err != nil { |
29 | | - panic(err) |
30 | | - } |
| 27 | + accessToken, err := flow.DetectFlow() |
| 28 | + if err != nil { |
| 29 | + panic(err) |
| 30 | + } |
31 | 31 |
|
32 | | - fmt.Printf("Access token: %s\n", accessToken.Token) |
| 32 | + fmt.Printf("Access token: %s\n", accessToken.Token) |
33 | 33 | } |
0 commit comments