diff --git a/main.go b/main.go index 54daa0d..13657f5 100644 --- a/main.go +++ b/main.go @@ -30,9 +30,9 @@ func run() error { http.HandleFunc("/", srv.serveHTTP) - port := 8080 + port := 8090 log.Printf("servering http port %v", port) - err = http.ListenAndServe(":8080", nil) + err = http.ListenAndServe(":8090", nil) if err != nil { return err } diff --git a/routes.auth.go b/routes.auth.go index eb2af41..0df506d 100644 --- a/routes.auth.go +++ b/routes.auth.go @@ -40,6 +40,7 @@ type Claims struct { Sub string `json:"sub"` IDEntreprise string `json:"idEntreprise"` RcaPartnerID string `json:"rcaPartnerId"` + Scopes []string `json:"scopes"` Roles []string `json:"roles"` jwt.StandardClaims } @@ -68,32 +69,36 @@ func (s *server) handleLocal() http.HandlerFunc { sub := r.FormValue("sub") idEntreprise := r.FormValue("id_entreprise") rcaPartnerID := r.FormValue("rcaPartnerId") - var jwtKey = []byte(r.FormValue("secret")) + jwtKey := r.FormValue("secret") + scopes := r.FormValue("scopes") + roles := r.FormValue("roles") + + var sc []string + sc = append(sc, scopes) + + rs := strings.Fields(roles) // Declare the expiration time of the token // here, we have kept it as 5 minutes expirationTime := time.Now().Add(5 * time.Hour) - roles := []string{"RCA_CLOUD_EXPERT_COMPTABLE", - "E_COLLECTE_BO_CREA", - "E_CREATION_CREA", - "E_QUESTIONNAIRE_CREA"} // Create the JWT claims, which includes the username and expiry time claims := &Claims{ Sub: sub, IDEntreprise: idEntreprise, RcaPartnerID: rcaPartnerID, - Roles: roles, + Roles: rs, + Scopes: sc, StandardClaims: jwt.StandardClaims{ // In JWT, the expiry time is expressed as unix milliseconds ExpiresAt: expirationTime.Unix(), }, } + secretBase64, err := jwt.DecodeSegment(jwtKey) // Declare the token with the algorithm used for signing, and the claims - ts := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - + ts := jwt.NewWithClaims(jwt.SigningMethodHS512, claims) + at, err := ts.SignedString(secretBase64) // Create the JWT string - at, err := ts.SignedString(jwtKey) if err != nil { log.Printf("erreur %v", err) // If there is an error in creating the JWT return an internal server error @@ -116,7 +121,7 @@ func (s *server) handleLocal() http.HandlerFunc { monID := strconv.Itoa(int(o.ID)) // Puis redisrect vers page resultat - rj := "http://localhost:8080/jwt?model=" + monID + rj := "http://localhost:8090/jwt?model=" + monID http.Redirect(rw, r, rj, http.StatusMovedPermanently) } @@ -163,8 +168,8 @@ func (s *server) handleOAuth20() http.HandlerFunc { rhttp := "https://" + d + "/entreprise-partenaire/authorize?client_id=" + ci + "&scope=" + sc + "¤t_company=" + cc + - "&redirect_uri=http://localhost:8080/oauth/redirect%3Fstate=" + st + - "&abort_uri=http://localhost:8080/index" + "&redirect_uri=http://localhost:8090/oauth/redirect%3Fstate=" + st + + "&abort_uri=http://localhost:8090/index" http.Redirect(rw, r, rhttp, http.StatusMovedPermanently) } @@ -239,7 +244,7 @@ func (s *server) handleRedirect() http.HandlerFunc { monID := strconv.Itoa(int(o.ID)) // Puis redisrect vers page resultat - rj := "http://localhost:8080/jwt?model=" + monID + rj := "http://localhost:8090/jwt?model=" + monID http.Redirect(rw, r, rj, http.StatusMovedPermanently) } } @@ -300,7 +305,7 @@ func constJSONToken(code, state string, param *model.Param) JSONToken { ClientID: param.ClientID, ClientSecret: param.ClientSecret, GrantType: param.GrantType, - RedirectURI: "http://localhost:8080/oauth/redirect%3Fstate=" + state, + RedirectURI: "http://localhost:8090/oauth/redirect%3Fstate=" + state, Code: code, } } diff --git a/templateOAuth/index.go b/templateOAuth/index.go index 22d8d91..82f4cf3 100644 --- a/templateOAuth/index.go +++ b/templateOAuth/index.go @@ -16,64 +16,12 @@ var TemplateIndex = ` @@ -87,21 +35,35 @@ var TemplateIndex = `
account_circle - +
account_balance - +
+
+
+ fiber_pin + + +
+
+
+
+ fiber_pin + + +
+
account_balance - +
diff --git a/templateOAuth/jwt.html b/templateOAuth/jwt.html deleted file mode 100644 index 24e2063..0000000 --- a/templateOAuth/jwt.html +++ /dev/null @@ -1,166 +0,0 @@ - - - - - RCA JWT API - - - - - - - - - - - - - -
-

JWT

-
-
-
-
-
-
- account_circle - - -
-
-
-
- account_balance - - -
-
-
-
- account_balance - - -
-
-
-
- fiber_pin - - -
-
- -
- -
-
-
- account_balance - - -
-
-
-
- account_balance - - -
-
-
-
- account_balance - - -
-
-
-
- account_balance - - -
-
-
-
- -
-
- -
-
- -
- - - - \ No newline at end of file diff --git a/templateOAuth/resultat.go b/templateOAuth/resultat.go index 901b2e1..cac371a 100644 --- a/templateOAuth/resultat.go +++ b/templateOAuth/resultat.go @@ -27,10 +27,10 @@ var Resultat = `

Composition

- + content_copy - + refreshRefresh Token
@@ -73,7 +73,11 @@ var Resultat = ` document.addEventListener('DOMContentLoaded', function () { var elems = document.querySelectorAll('.collapsible'); var instances = M.Collapsible.init(elems, {}); + + var elemsTt = document.querySelectorAll('.tooltipped'); + var instancesTt = M.Tooltip.init(elemsTt, {}); }); + ` diff --git a/templateOAuth/resultat.html b/templateOAuth/resultat.html deleted file mode 100644 index 4250799..0000000 --- a/templateOAuth/resultat.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - RCA JWT API - - - - - - - - - - - - - -
-

Composition

-
-
-
- - content_copy - -
- - {{.JwtProduce }} - -
-
- -
    -
  • -
    filter_dramaheader
    -
    -
  • -
  • -
    placepayload
    -
    -
  • -
  • -
    whatshotsignature
    -
    Lorem ipsum dolor sit amet.
    -
  • -
-
-
-
- - - - - \ No newline at end of file