Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
BagToad committed Oct 8, 2024
1 parent 7e4a31f commit 9585a35
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions examples_test.go
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)
}
2 changes: 1 addition & 1 deletion oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewGitHubHost(hostURL string) (*Host, error) {
}

// GitHubHost constructs a Host from the given URL to a GitHub instance.
//
//
// Deprecated: `GitHubHost` can panic with a malformed `hostURL`. Use `NewGitHubHost` instead for graceful error handling.
func GitHubHost(hostURL string) *Host {
u, _ := url.Parse(hostURL)
Expand Down

0 comments on commit 9585a35

Please sign in to comment.