Commit 38317183 authored by Gurvinder Singh's avatar Gurvinder Singh
Browse files

added support for specifying life time of requested token

parent 5062c679
......@@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
auth "scm.uninett.no/laas/laasctl-auth"
......@@ -83,6 +84,12 @@ func (jwm *JWTMiddleware) getJWTToken(
}
now := time.Now()
lifeParam := r.URL.Query().Get("lifetime")
lifeTime, _ := strconv.ParseUint(lifeParam, 10, 32)
if lifeTime == 0 {
lifeTime = uint64(conf.GetIntValue("engine.token_age"))
}
claims := jws.Claims{}
// Set the claims
claims.SetSubject(user)
......@@ -92,7 +99,7 @@ func (jwm *JWTMiddleware) getJWTToken(
claims.Set("acr_values", r.Header.Get("X-Dataporten-Acr-Values"))
claims.Set("userid-sec", r.Header.Get("X-Dataporten-Userid-Sec"))
claims.SetIssuer(conf.GetStringValue("engine.issuer_url"))
claims.SetExpiration(now.Add(time.Duration(conf.GetIntValue("engine.token_age")) * time.Second))
claims.SetExpiration(now.Add(time.Duration(lifeTime) * time.Second))
jwt := jws.NewJWT(claims, crypto.SigningMethodRS256)
token, err := jwt.Serialize(jwm.RSAKey)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment