chore(linting): apply gofumpt & goimports to all .go files (#225)
This commit is contained in:
parent
c4b7ef9160
commit
b5da6ec29b
45 changed files with 539 additions and 479 deletions
|
@ -34,14 +34,14 @@ func main() {
|
|||
|
||||
router := mux.NewRouter()
|
||||
|
||||
//public url accessible without any authorization
|
||||
//will print `OK` and current timestamp
|
||||
// public url accessible without any authorization
|
||||
// will print `OK` and current timestamp
|
||||
router.HandleFunc(publicURL, func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("OK " + time.Now().String()))
|
||||
})
|
||||
|
||||
//protected url which needs an active token
|
||||
//will print the result of the introspection endpoint on success
|
||||
// protected url which needs an active token
|
||||
// will print the result of the introspection endpoint on success
|
||||
router.HandleFunc(protectedURL, func(w http.ResponseWriter, r *http.Request) {
|
||||
ok, token := checkToken(w, r)
|
||||
if !ok {
|
||||
|
@ -60,9 +60,9 @@ func main() {
|
|||
w.Write(data)
|
||||
})
|
||||
|
||||
//protected url which needs an active token and checks if the response of the introspect endpoint
|
||||
//contains a requested claim with the required (string) value
|
||||
//e.g. /protected/username/livio@caos.ch
|
||||
// protected url which needs an active token and checks if the response of the introspect endpoint
|
||||
// contains a requested claim with the required (string) value
|
||||
// e.g. /protected/username/livio@caos.ch
|
||||
router.HandleFunc(protectedClaimURL, func(w http.ResponseWriter, r *http.Request) {
|
||||
ok, token := checkToken(w, r)
|
||||
if !ok {
|
||||
|
|
|
@ -48,18 +48,18 @@ func main() {
|
|||
logrus.Fatalf("error creating provider %s", err.Error())
|
||||
}
|
||||
|
||||
//generate some state (representing the state of the user in your application,
|
||||
//e.g. the page where he was before sending him to login
|
||||
// generate some state (representing the state of the user in your application,
|
||||
// e.g. the page where he was before sending him to login
|
||||
state := func() string {
|
||||
return uuid.New().String()
|
||||
}
|
||||
|
||||
//register the AuthURLHandler at your preferred path
|
||||
//the AuthURLHandler creates the auth request and redirects the user to the auth server
|
||||
//including state handling with secure cookie and the possibility to use PKCE
|
||||
// register the AuthURLHandler at your preferred path
|
||||
// the AuthURLHandler creates the auth request and redirects the user to the auth server
|
||||
// including state handling with secure cookie and the possibility to use PKCE
|
||||
http.Handle("/login", rp.AuthURLHandler(state, provider))
|
||||
|
||||
//for demonstration purposes the returned userinfo response is written as JSON object onto response
|
||||
// for demonstration purposes the returned userinfo response is written as JSON object onto response
|
||||
marshalUserinfo := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string, rp rp.RelyingParty, info oidc.UserInfo) {
|
||||
data, err := json.Marshal(info)
|
||||
if err != nil {
|
||||
|
@ -69,9 +69,9 @@ func main() {
|
|||
w.Write(data)
|
||||
}
|
||||
|
||||
//you could also just take the access_token and id_token without calling the userinfo endpoint:
|
||||
// you could also just take the access_token and id_token without calling the userinfo endpoint:
|
||||
//
|
||||
//marshalToken := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string, rp rp.RelyingParty) {
|
||||
// marshalToken := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string, rp rp.RelyingParty) {
|
||||
// data, err := json.Marshal(tokens)
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
@ -80,16 +80,16 @@ func main() {
|
|||
// w.Write(data)
|
||||
//}
|
||||
|
||||
//register the CodeExchangeHandler at the callbackPath
|
||||
//the CodeExchangeHandler handles the auth response, creates the token request and calls the callback function
|
||||
//with the returned tokens from the token endpoint
|
||||
//in this example the callback function itself is wrapped by the UserinfoCallback which
|
||||
//will call the Userinfo endpoint, check the sub and pass the info into the callback function
|
||||
// register the CodeExchangeHandler at the callbackPath
|
||||
// the CodeExchangeHandler handles the auth response, creates the token request and calls the callback function
|
||||
// with the returned tokens from the token endpoint
|
||||
// in this example the callback function itself is wrapped by the UserinfoCallback which
|
||||
// will call the Userinfo endpoint, check the sub and pass the info into the callback function
|
||||
http.Handle(callbackPath, rp.CodeExchangeHandler(rp.UserinfoCallback(marshalUserinfo), provider))
|
||||
|
||||
//if you would use the callback without calling the userinfo endpoint, simply switch the callback handler for:
|
||||
// if you would use the callback without calling the userinfo endpoint, simply switch the callback handler for:
|
||||
//
|
||||
//http.Handle(callbackPath, rp.CodeExchangeHandler(marshalToken, provider))
|
||||
// http.Handle(callbackPath, rp.CodeExchangeHandler(marshalToken, provider))
|
||||
|
||||
lis := fmt.Sprintf("127.0.0.1:%s", port)
|
||||
logrus.Infof("listening on http://%s/", lis)
|
||||
|
|
|
@ -16,9 +16,7 @@ import (
|
|||
"github.com/zitadel/oidc/pkg/client/profile"
|
||||
)
|
||||
|
||||
var (
|
||||
client = http.DefaultClient
|
||||
)
|
||||
var client = http.DefaultClient
|
||||
|
||||
func main() {
|
||||
keyPath := os.Getenv("KEY_PATH")
|
||||
|
@ -145,7 +143,6 @@ func main() {
|
|||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
})
|
||||
lis := fmt.Sprintf("127.0.0.1:%s", port)
|
||||
logrus.Infof("listening on http://%s/", lis)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue