requests.go 2.84 KB
Newer Older
1
2
package protocol

Sietse Ringers's avatar
Sietse Ringers committed
3
import (
4
	"time"
Sietse Ringers's avatar
Sietse Ringers committed
5
6
7
8

	"github.com/credentials/irmago"
)

Sietse Ringers's avatar
Sietse Ringers committed
9
// ServerJwt contains standard JWT fields.
10
type ServerJwt struct {
11
12
13
	Type       string           `json:"sub"`
	ServerName string           `json:"iss"`
	IssuedAt   irmago.Timestamp `json:"iat"`
Sietse Ringers's avatar
Sietse Ringers committed
14
15
}

Sietse Ringers's avatar
Sietse Ringers committed
16
// A ServiceProviderRequest contains a disclosure request.
17
type ServiceProviderRequest struct {
18
	Request *irmago.DisclosureRequest `json:"request"`
Sietse Ringers's avatar
Sietse Ringers committed
19
20
}

Sietse Ringers's avatar
Sietse Ringers committed
21
// A SignatureRequestorRequest contains a signing request.
Sietse Ringers's avatar
Sietse Ringers committed
22
type SignatureRequestorRequest struct {
23
	Request *irmago.SignatureRequest `json:"request"`
24
25
}

Sietse Ringers's avatar
Sietse Ringers committed
26
// An IdentityProviderRequest contains an issuance request.
27
type IdentityProviderRequest struct {
28
	Request *irmago.IssuanceRequest `json:"request"`
29
30
}

Sietse Ringers's avatar
Sietse Ringers committed
31
// ServiceProviderJwt is a requestor JWT for a disclosure session.
32
33
34
35
36
type ServiceProviderJwt struct {
	ServerJwt
	Request ServiceProviderRequest `json:"sprequest"`
}

Sietse Ringers's avatar
Sietse Ringers committed
37
// SignatureRequestorJwt is a requestor JWT for a signing session.
Sietse Ringers's avatar
Sietse Ringers committed
38
type SignatureRequestorJwt struct {
39
	ServerJwt
Sietse Ringers's avatar
Sietse Ringers committed
40
	Request SignatureRequestorRequest `json:"absrequest"`
41
42
}

Sietse Ringers's avatar
Sietse Ringers committed
43
// IdentityProviderJwt is a requestor JWT for issuance session.
44
45
46
type IdentityProviderJwt struct {
	ServerJwt
	Request IdentityProviderRequest `json:"iprequest"`
47
48
}

Sietse Ringers's avatar
Sietse Ringers committed
49
// NewServiceProviderJwt returns a new ServiceProviderJwt.
50
func NewServiceProviderJwt(servername string, dr *irmago.DisclosureRequest) *ServiceProviderJwt {
51
52
	return &ServiceProviderJwt{
		ServerJwt: ServerJwt{
53
			ServerName: servername,
54
			IssuedAt:   irmago.Timestamp(time.Now()),
55
56
			Type:       "verification_request",
		},
57
		Request: ServiceProviderRequest{Request: dr},
58
	}
Sietse Ringers's avatar
Sietse Ringers committed
59
60
}

Sietse Ringers's avatar
Sietse Ringers committed
61
// NewSignatureRequestorJwt returns a new SignatureRequestorJwt.
Sietse Ringers's avatar
Sietse Ringers committed
62
63
func NewSignatureRequestorJwt(servername string, sr *irmago.SignatureRequest) *SignatureRequestorJwt {
	return &SignatureRequestorJwt{
64
65
		ServerJwt: ServerJwt{
			ServerName: servername,
66
			IssuedAt:   irmago.Timestamp(time.Now()),
67
68
			Type:       "signature_request",
		},
Sietse Ringers's avatar
Sietse Ringers committed
69
		Request: SignatureRequestorRequest{Request: sr},
70
71
72
	}
}

Sietse Ringers's avatar
Sietse Ringers committed
73
// NewIdentityProviderJwt returns a new IdentityProviderJwt.
74
func NewIdentityProviderJwt(servername string, ir *irmago.IssuanceRequest) *IdentityProviderJwt {
Sietse Ringers's avatar
Sietse Ringers committed
75
76
77
	return &IdentityProviderJwt{
		ServerJwt: ServerJwt{
			ServerName: servername,
78
			IssuedAt:   irmago.Timestamp(time.Now()),
Sietse Ringers's avatar
Sietse Ringers committed
79
			Type:       "issue_request",
Sietse Ringers's avatar
Sietse Ringers committed
80
81
82
83
84
		},
		Request: IdentityProviderRequest{Request: ir},
	}
}

Sietse Ringers's avatar
Sietse Ringers committed
85
// A RequestorJwt contains an IRMA session object.
Sietse Ringers's avatar
Sietse Ringers committed
86
87
type RequestorJwt interface {
	IrmaSession() irmago.Session
88
89
}

Sietse Ringers's avatar
Sietse Ringers committed
90
91
92
93
// IrmaSession returns an IRMA session object.
func (jwt *ServiceProviderJwt) IrmaSession() irmago.Session { return jwt.Request.Request }

// IrmaSession returns an IRMA session object.
Sietse Ringers's avatar
Sietse Ringers committed
94
func (jwt *SignatureRequestorJwt) IrmaSession() irmago.Session { return jwt.Request.Request }
Sietse Ringers's avatar
Sietse Ringers committed
95
96
97

// IrmaSession returns an IRMA session object.
func (jwt *IdentityProviderJwt) IrmaSession() irmago.Session { return jwt.Request.Request }