Skip to content

Commit

Permalink
refactor: update json meta, error msg fmt, cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Oct 12, 2021
1 parent a6b1524 commit c8e4b92
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions goic.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package goic

import (
"bytes"
"crypto/rsa"
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -78,7 +76,7 @@ type Token struct {
IDToken string `json:"id_token"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Provider string
Provider string `json:"provider,omitempty"`
idToken map[string]interface{}
}

Expand All @@ -92,7 +90,7 @@ type User struct {
Name string `json:"name"`
Picture string `json:"picture,omitempty"`
Subject string `json:"sub,omitempty"`
Error error
Error error `json:"-"`
}

// New gives new GOIC instance
Expand Down Expand Up @@ -358,7 +356,7 @@ func (g *Goic) process(res http.ResponseWriter, req *http.Request) {
}

if g.verbose {
log.Println("[err] goic request auth callback: " + msg)
log.Printf("[err] goic request auth callback: %s", msg)
}
http.Error(res, msg, http.StatusInternalServerError)
return
Expand All @@ -368,7 +366,7 @@ func (g *Goic) process(res http.ResponseWriter, req *http.Request) {
if code == "" {
if err := g.RequestAuth(name, res, req); err != nil {
if g.verbose {
log.Println("[err] goic request auth: %v\n", err)
log.Printf("[err] goic request auth: %v\n", err)
}
http.Error(res, err.Error(), http.StatusInternalServerError)
}
Expand All @@ -387,15 +385,15 @@ func (g *Goic) process(res http.ResponseWriter, req *http.Request) {
tok, err := g.Authenticate(name, code, nonce, req)
if err != nil {
if g.verbose {
log.Printf("[err] goic request auth: %v\n", err)
log.Printf("[err] goic authenticate: %v\n", err)
}
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}

if g.userCallback == nil {
res.WriteHeader(http.StatusOK)
_, _ = fmt.Fprintln(res, "OK, the auth flow is complete. However, backend is yet to request userinfo")
_, _ = res.Write([]byte("OK, the auth flow is complete. However, backend is yet to request userinfo"))
return
}

Expand Down

0 comments on commit c8e4b92

Please sign in to comment.