Esempio n. 1
0
func extractKey(key string, claims jwt.Claims) *string {
	if claims.Has(key) {
		val := claims.Get(key)
		if s, ok := val.(string); ok {
			return models.String(s)
		}
	}
	return nil
}
Esempio n. 2
0
func TestGetAndSetTime(t *testing.T) {
	now := time.Now()
	nowUnix := now.Unix()
	c := jwt.Claims{
		"int":     int(nowUnix),
		"int32":   int32(nowUnix),
		"int64":   int64(nowUnix),
		"uint":    uint(nowUnix),
		"uint32":  uint32(nowUnix),
		"uint64":  uint64(nowUnix),
		"float64": float64(nowUnix),
	}
	c.SetTime("setTime", now)
	for k := range c {
		v, ok := c.GetTime(k)
		if got, want := v, time.Unix(nowUnix, 0); !ok || !got.Equal(want) {
			t.Errorf("%s: got %v want %v", k, got, want)
		}
	}
}