Beispiel #1
0
func RefreshToken(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
	requestUser := new(models.User)
	decoder := json.NewDecoder(r.Body)
	decoder.Decode(&requestUser)

	w.Header().Set("Content-Type", "application/json")
	w.Write(services.RefreshToken(requestUser))
}
func (suite *AuthenticationServicesTestSuite) TestRefreshToken(c *C) {
	user := models.User{
		Username: "******",
		Password: "******",
	}
	authBackend := authentication.InitJWTAuthenticationBackend()
	tokenString, err := authBackend.GenerateToken(user.UUID)
	token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
		return authBackend.PublicKey, nil
	})
	assert.Nil(t, err)

	newToken := services.RefreshToken(token)
	assert.NotEmpty(t, newToken)
}
func (suite *AuthenticationServicesTestSuite) TestRefreshTokenInvalidToken(c *C) {
	token := jwt.New(jwt.GetSigningMethod("RS256"))
	newToken := services.RefreshToken(token)
	assert.Empty(t, newToken)
}