Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shinfan committed Aug 9, 2018
1 parent 0efbe8b commit 2518127
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 0 additions & 4 deletions go/oauth2l/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ Its primary use is to fetch and
print OAuth 2.0 access tokens, which can be used with other command-line
tools and shell scripts.

This tool also demonstrates how to design a simple and easy-to-use OAuth
2.0 client experience with [Google Authenticator](https://github.com/shinfan/sgauth/).
Please use [this package](oauth2l/) as reference code.

## Overview

`oauth2l` supports all Google OAuth 2.0 authentication flows for both user
Expand Down
26 changes: 20 additions & 6 deletions go/oauth2l/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func help() {
"[--jwt] [--json] [--sso] [--ssocli] {scope|aud|email}")
}

func readJSON(file string) (string) {
func readJSON(file string) (string, error) {
if file != "" {
secretBytes, err := ioutil.ReadFile(file)
if err != nil {
panic(fmt.Sprintf("Failed to read file %s.\n", file))
return "", err
}
return string(secretBytes)
return string(secretBytes), nil
}
return ""
return "", nil
}

// Default 3LO authorization handler. Prints the authorization URL on stdout
Expand Down Expand Up @@ -107,8 +107,15 @@ func main() {
if task, ok := fetchTasks[cmd]; ok {
if *jwtFlag {
// JWT flow
json, err := readJSON(*jsonFile)
if err != nil {
fmt.Println("Failed to open file: " + *jsonFile)
fmt.Println(err.Error())
return
}

settings := &sgauth.Settings{
CredentialsJSON: readJSON(*jsonFile),
CredentialsJSON: json,
Audience: flagSet.Args()[len(flagSet.Args()) - 1],
}
task(settings)
Expand All @@ -118,10 +125,17 @@ func main() {
parseScopes(flagSet.Args()[1:]))
} else {
// OAuth flow
json, err := readJSON(*jsonFile)
if err != nil {
fmt.Println("Failed to open file: " + *jsonFile)
fmt.Println(err.Error())
return
}

// 3LO or 2LO depending on the credential type.
// For 2LO flow OAuthFlowHandler and State are not needed.
settings := &sgauth.Settings{
CredentialsJSON: readJSON(*jsonFile),
CredentialsJSON: json,
Scope: parseScopes(flagSet.Args()),
OAuthFlowHandler: defaultAuthorizeFlowHandler,
State: "state",
Expand Down

0 comments on commit 2518127

Please sign in to comment.