From 6d4795b0a6b9d42e563040849bd960a229672329 Mon Sep 17 00:00:00 2001 From: Laurent Drogou Date: Sat, 30 Jan 2021 00:34:00 +0100 Subject: [PATCH] mise en place du refresh token --- routes.auth.go | 18 ++++++------------ store/store.go | 2 -- templateOAuth/resultat.go | 12 +++++++++++- templateOAuth/resultat.html | 3 +++ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/routes.auth.go b/routes.auth.go index 9ac0ed3..eb2af41 100644 --- a/routes.auth.go +++ b/routes.auth.go @@ -209,11 +209,14 @@ func (s *server) handleRedirect() http.HandlerFunc { log.Printf("client erreur %v", err) } - log.Printf("resp status %v", resp.StatusCode) + if resp.StatusCode != 200 { + log.Printf("Problème dans la requete retour http %v", resp.StatusCode) + s.response(rw, r, nil, http.StatusBadGateway) + return + } var t map[string]interface{} // here's the trick - json.NewDecoder(resp.Body).Decode(&t) - + err = json.NewDecoder(resp.Body).Decode(&t) if err != nil { log.Printf("Cannot parse token body err=%v", err) s.response(rw, r, nil, http.StatusBadGateway) @@ -221,11 +224,6 @@ func (s *server) handleRedirect() http.HandlerFunc { } defer resp.Body.Close() - if err != nil { - log.Printf("Cannot parse token body err=%v", err) - s.response(rw, r, nil, http.StatusBadGateway) - return - } // Insert en base de données o := &model.Oauth{ ID: 0, @@ -267,10 +265,6 @@ func (s *server) handleJSONWebToken() http.HandlerFunc { } tokenVal := oauth.AccessToken - fmt.Println("============") - fmt.Println(tokenVal) - fmt.Println("============") - tableau := strings.Split(tokenVal, ".") header, err := jwt.DecodeSegment(tableau[0]) if err != nil { diff --git a/store/store.go b/store/store.go index 78215e7..d74d401 100644 --- a/store/store.go +++ b/store/store.go @@ -67,12 +67,10 @@ func (store *DbStore) Close() error { func (store *DbStore) GetOauth(id int64) (*model.Oauth, error) { var oauth = &model.Oauth{} - log.Println("ME VOICI") err := store.db.Get(oauth, "SELECT * FROM oauth where id=$1", id) if err != nil { return oauth, err } - log.Printf("oauth=%v", oauth) return oauth, nil } diff --git a/templateOAuth/resultat.go b/templateOAuth/resultat.go index 834b6c3..901b2e1 100644 --- a/templateOAuth/resultat.go +++ b/templateOAuth/resultat.go @@ -15,7 +15,11 @@ var Resultat = ` - + @@ -23,6 +27,12 @@ var Resultat = `

Composition

+ + content_copy + + + refreshRefresh Token +
diff --git a/templateOAuth/resultat.html b/templateOAuth/resultat.html index 7463501..4250799 100644 --- a/templateOAuth/resultat.html +++ b/templateOAuth/resultat.html @@ -21,6 +21,9 @@
+ + content_copy +
{{.JwtProduce }}