Commit 00988615 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add Action field to jwts and make them implement jwt.Claims

parent f634e01e
......@@ -252,14 +252,14 @@ func JwtDecode(jwt string, body interface{}) error {
return json.Unmarshal(bodybytes, body)
}
func ParseRequestorJwt(action Action, jwt string) (RequestorJwt, error) {
func ParseRequestorJwt(action string, jwt string) (RequestorJwt, error) {
var retval RequestorJwt
switch action {
case ActionDisclosing:
case "verification_request":
retval = &ServiceProviderJwt{}
case ActionSigning:
case "signature_request":
retval = &SignatureRequestorJwt{}
case ActionIssuing:
case "issue_request":
retval = &IdentityProviderJwt{}
default:
return nil, errors.New("Invalid session type")
......
......@@ -487,8 +487,10 @@ func NewIdentityProviderJwt(servername string, ir *IssuanceRequest) *IdentityPro
// A RequestorJwt contains an IRMA session object.
type RequestorJwt interface {
Action() Action
SessionRequest() SessionRequest
Requestor() string
Valid() error
}
func (jwt *ServerJwt) Requestor() string { return jwt.ServerName }
......@@ -501,3 +503,39 @@ func (jwt *SignatureRequestorJwt) SessionRequest() SessionRequest { return jwt.R
// SessionRequest returns an IRMA session object.
func (jwt *IdentityProviderJwt) SessionRequest() SessionRequest { return jwt.Request.Request }
func (jwt *ServiceProviderJwt) Valid() error {
if jwt.Type != "verification_request" {
return errors.New("Verification jwt has invalid subject")
}
if time.Time(jwt.IssuedAt).After(time.Now()) {
return errors.New("Verification jwt not yet valid")
}
return nil
}
func (jwt *SignatureRequestorJwt) Valid() error {
if jwt.Type != "signature_request" {
return errors.New("Signature jwt has invalid subject")
}
if time.Time(jwt.IssuedAt).After(time.Now()) {
return errors.New("Signature jwt not yet valid")
}
return nil
}
func (jwt *IdentityProviderJwt) Valid() error {
if jwt.Type != "issue_request" {
return errors.New("Issuance jwt has invalid subject")
}
if time.Time(jwt.IssuedAt).After(time.Now()) {
return errors.New("Issuance jwt not yet valid")
}
return nil
}
func (jwt *ServiceProviderJwt) Action() Action { return ActionDisclosing }
func (jwt *SignatureRequestorJwt) Action() Action { return ActionSigning }
func (jwt *IdentityProviderJwt) Action() Action { return ActionIssuing }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment