예제 #1
0
파일: jwt.go 프로젝트: lestrrat/go-jwx
// MarshalJSON generates JSON representation of this claim set
func (c *ClaimSet) MarshalJSON() ([]byte, error) {
	// Reverting time back for machines whose time is not perfectly in sync.
	// If client machine's time is in the future according
	// to Google servers, an access token will not be issued.
	now := time.Now().Add(-10 * time.Second)
	if c.IssuedAt == 0 {
		c.IssuedAt = now.Unix()
	}
	if c.Expiration == 0 {
		c.Expiration = now.Add(time.Hour).Unix()
	}
	if c.Expiration < c.IssuedAt {
		return nil, fmt.Errorf("invalid expiration = %v; must be later than issued_at = %v", c.Expiration, c.IssuedAt)
	}

	return emap.MergeMarshal(c.EssentialClaims, c.PrivateClaims)
}
예제 #2
0
파일: message.go 프로젝트: nabeken/go-jwx
func (h Header) MarshalJSON() ([]byte, error) {
	return emap.MergeMarshal(h.EssentialHeader, h.PrivateParams)
}