Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3641

How to refresh a token when token expires in a go backend application

$
0
0

In my go backend application I generated a token when my app is initialised.And I want to use this token as a global variable for further authentications.

type Token struct {    Name         string    Value        string    RefreshValue string    Expires      time.Time}func main() {   AppToken := GetToken()   router := mux.NewRouter()   router.HandleFunc("/employees", GetEmployeesHandler).Methods("GET")}func GetEmployeesHandler (w http.ResponseWriter, r *http.Request) {    w.WriteHeader(http.StatusOK)    //here i want to pass token, here i validate token and check token is expired    //check token function checks token is valid and if token     //expired,  check token updates AppToken.    err := CheckToken(AppToken)    if err != nil {       return err    }    fmt.Fprintf(w, "API is up and running")}

My requirement is that whenever the token expires I want to refresh the token I also want to ensure the refresh token should be blocked when there is already a refresh token process that is taking place. Please help me.


Viewing all articles
Browse latest Browse all 3641

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>