mise en place du refresh token

This commit is contained in:
2021-02-06 22:44:01 +01:00
parent 6041afc4f6
commit 737fb71694
3 changed files with 21 additions and 3 deletions

View File

@@ -97,6 +97,7 @@ func (s *server) handleLocal() http.HandlerFunc {
secretBase64, err := jwt.DecodeSegment(jwtKey) secretBase64, err := jwt.DecodeSegment(jwtKey)
// Declare the token with the algorithm used for signing, and the claims // Declare the token with the algorithm used for signing, and the claims
ts := jwt.NewWithClaims(jwt.SigningMethodHS512, claims) ts := jwt.NewWithClaims(jwt.SigningMethodHS512, claims)
at, err := ts.SignedString(secretBase64) at, err := ts.SignedString(secretBase64)
// Create the JWT string // Create the JWT string
if err != nil { if err != nil {
@@ -249,11 +250,16 @@ func (s *server) handleRedirect() http.HandlerFunc {
} }
} }
func (s *server) handleRefreshToken() http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) {
}
}
func (s *server) handleJSONWebToken() http.HandlerFunc { func (s *server) handleJSONWebToken() http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) { return func(rw http.ResponseWriter, r *http.Request) {
c := r.URL.Query().Get("model") c := r.URL.Query().Get("model")
//c, _ := mux.Vars(r)["model"]
rw.Header().Set("Content-Type", "text/html") rw.Header().Set("Content-Type", "text/html")
rw.WriteHeader(http.StatusOK) rw.WriteHeader(http.StatusOK)

View File

@@ -6,5 +6,6 @@ func (s *server) routes() {
s.router.HandleFunc("/local", s.handleLocal()).Methods("POST") s.router.HandleFunc("/local", s.handleLocal()).Methods("POST")
s.router.HandleFunc("/oauth20", s.handleOAuth20()).Methods("POST") s.router.HandleFunc("/oauth20", s.handleOAuth20()).Methods("POST")
s.router.HandleFunc("/jwt", s.handleJSONWebToken()).Methods("GET") s.router.HandleFunc("/jwt", s.handleJSONWebToken()).Methods("GET")
s.router.HandleFunc("/oauth/refresh/{id}", s.handleRefreshToken()).Methods("POST")
} }

View File

@@ -16,9 +16,20 @@ var Resultat = `<!DOCTYPE html>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha512.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha512.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64-min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64-min.js"></script>
<script> <script>
function copy(jwt) { function copy(jwt){
navigator.clipboard.writeText(jwt) navigator.clipboard.writeText(jwt)
} }
function test(){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8080/oauth/refresh/1');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
alert(xhr.responseText);
}
};
xhr.send();
}
</script> </script>
</head> </head>
@@ -30,7 +41,7 @@ var Resultat = `<!DOCTYPE html>
<a class="waves-effect waves-light btn tooltipped" data-tooltip="Copy" onclick="copy('{{.JwtProduce }}');" > <a class="waves-effect waves-light btn tooltipped" data-tooltip="Copy" onclick="copy('{{.JwtProduce }}');" >
<i class="material-icons center">content_copy</i> <i class="material-icons center">content_copy</i>
</a> </a>
<a class="waves-effect waves-light btn tooltipped" data-tooltip="Refresh" onclick="copy('{{.JwtProduce }}');" > <a class="waves-effect waves-light btn tooltipped" data-tooltip="Refresh" onclick="refresh('{{.JwtProduce }}');" >
<i class="material-icons left bottom">refresh</i>Refresh Token <i class="material-icons left bottom">refresh</i>Refresh Token
</a> </a>
<div class="row"> <div class="row">