-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
package oauth_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/cli/oauth" | ||
"github.com/cli/oauth" | ||
) | ||
|
||
// DetectFlow attempts to initiate OAuth Device flow with the server and falls back to OAuth Web | ||
// application flow if Device flow seems unsupported. This approach isn't strictly needed for | ||
// github.com, as its Device flow support is globally available, but it enables logging in to | ||
// self-hosted GitHub instances as well. | ||
func ExampleFlow_DetectFlow() { | ||
host, err := oauth.NewGitHubHost("https://github.com") | ||
if err != nil { | ||
panic(err) | ||
} | ||
flow := &oauth.Flow{ | ||
Host: host, | ||
ClientID: os.Getenv("OAUTH_CLIENT_ID"), | ||
ClientSecret: os.Getenv("OAUTH_CLIENT_SECRET"), // only applicable to web app flow | ||
CallbackURI: "http://127.0.0.1/callback", // only applicable to web app flow | ||
Scopes: []string{"repo", "read:org", "gist"}, | ||
} | ||
host, err := oauth.NewGitHubHost("https://github.com") | ||
if err != nil { | ||
panic(err) | ||
} | ||
flow := &oauth.Flow{ | ||
Host: host, | ||
ClientID: os.Getenv("OAUTH_CLIENT_ID"), | ||
ClientSecret: os.Getenv("OAUTH_CLIENT_SECRET"), // only applicable to web app flow | ||
CallbackURI: "http://127.0.0.1/callback", // only applicable to web app flow | ||
Scopes: []string{"repo", "read:org", "gist"}, | ||
} | ||
|
||
accessToken, err := flow.DetectFlow() | ||
if err != nil { | ||
panic(err) | ||
} | ||
accessToken, err := flow.DetectFlow() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Access token: %s\n", accessToken.Token) | ||
fmt.Printf("Access token: %s\n", accessToken.Token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters