Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"os"
"strconv"
"strings"

"github.com/cli/browser"
"github.com/go-jose/go-jose/v3"
"github.com/go-jose/go-jose/v3/jwt"
"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -148,7 +150,6 @@ func LogJson(value interface{}) {
}

output, err := json.Marshal(value)

if err != nil {
pterm.Error.Println(err)
return
Expand Down Expand Up @@ -397,7 +398,6 @@ func LogKey(name string, key interface{}) {
pterm.FgGray.Printfln("%s", p.String())
case *ecdsa.PublicKey:
b, err := x509.MarshalPKIXPublicKey(key)

if err != nil {
pterm.Error.Println(err)
}
Expand All @@ -414,7 +414,6 @@ func LogKey(name string, key interface{}) {
pterm.FgGray.Printfln("%s", p.String())
case *ecdsa.PrivateKey:
b, err := x509.MarshalECPrivateKey(key)

if err != nil {
pterm.Error.Println(err)
}
Expand Down Expand Up @@ -473,3 +472,18 @@ func LogSubjectTokenAndActorToken(request oauth2.Request) {
pterm.Println()
}
}

func LogAuthURL(url string, noBrowser bool) {
if noBrowser && silent {
fmt.Fprintln(os.Stderr, url)
} else {
Logfln("\nGo to the following URL:\n\n%s", url)
}

if !noBrowser {
Logfln("\nOpening browser...")
if err := browser.OpenURL(url); err != nil {
LogError(err)
}
}
}
10 changes: 1 addition & 9 deletions cmd/oauth2_authorize_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"net/http"

"github.com/cli/browser"
"github.com/cloudentity/oauth2c/internal/oauth2"
)

Expand Down Expand Up @@ -54,14 +53,7 @@ func (c *OAuth2Cmd) AuthorizationCodeGrantFlow(clientConfig oauth2.ClientConfig,
LogBox("PKCE", "code_verifier = %s\ncode_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))", codeVerifier)
}

Logfln("\nGo to the following URL:\n\n%s", authorizeRequest.URL.String())

if !clientConfig.NoBrowser {
Logfln("\nOpening browser...")
if err = browser.OpenURL(authorizeRequest.URL.String()); err != nil {
LogError(err)
}
}
LogAuthURL(authorizeRequest.URL.String(), clientConfig.NoBrowser)

Logln()

Expand Down
10 changes: 1 addition & 9 deletions cmd/oauth2_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/http"
"time"

"github.com/cli/browser"
"github.com/cloudentity/oauth2c/internal/oauth2"
)

Expand Down Expand Up @@ -36,14 +35,7 @@ func (c *OAuth2Cmd) DeviceGrantFlow(clientConfig oauth2.ClientConfig, serverConf
verificationUri = *authorizationResponse.VerificationURIComplete
}

Logfln("\nGo to the following URL:\n\n%s", verificationUri)

if !clientConfig.NoBrowser {
Logfln("\nOpening browser...")
if err = browser.OpenURL(verificationUri); err != nil {
LogError(err)
}
}
LogAuthURL(verificationUri, clientConfig.NoBrowser)

Logln()

Expand Down
10 changes: 1 addition & 9 deletions cmd/oauth2_implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"net/http"

"github.com/cli/browser"
"github.com/cloudentity/oauth2c/internal/oauth2"
)

Expand All @@ -25,14 +24,7 @@ func (c *OAuth2Cmd) ImplicitGrantFlow(clientConfig oauth2.ClientConfig, serverCo

LogRequest(authorizeRequest)

Logfln("\nGo to the following URL:\n\n%s", authorizeRequest.URL.String())

if !clientConfig.NoBrowser {
Logfln("\nOpening browser...")
if err = browser.OpenURL(authorizeRequest.URL.String()); err != nil {
LogError(err)
}
}
LogAuthURL(authorizeRequest.URL.String(), clientConfig.NoBrowser)

Logln()

Expand Down