示例#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)
}