forked from dexorcist/auth0
/
ticket.go
64 lines (52 loc) · 1.91 KB
/
ticket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package management
type Ticket struct {
// The user will be redirected to this endpoint once the ticket is used
ResultURL *string `json:"result_url,omitempty"`
// The UserID for which the ticket is to be created
UserID *string `json:"user_id,omitempty"`
// The ticket's lifetime in seconds starting from the moment of creation.
// After expiration the ticket can not be used to verify the users's email.
// If not specified or if you send 0 the Auth0 default lifetime will be
// applied.
TTLSec *int `json:"ttl_sec,omitempty"`
// The connection that provides the identity for which the password is to be
// changed. If sending this parameter, the email is also required and the
// UserID is invalid.
//
// Requires: Email
// Conflicts with: UserID
ConnectionID *string `json:"connection_id,omitempty"`
// The user's email
//
// Requires: ConnectionID
// Conflicts with: UserID
Email *string `json:"email,omitempty"`
// The URL that represents the ticket
Ticket *string `json:"ticket,omitempty"`
// Whether to set the email_verified attribute to true (true) or whether it
// should not be updated
MarkEmailAsVerified *bool `json:"mark_email_as_verified,omitempty"`
}
func (t *Ticket) String() string {
return Stringify(t)
}
type TicketManager struct {
m *Management
}
func NewTicketManager(m *Management) *TicketManager {
return &TicketManager{m}
}
// Create a ticket to verify a user's email address.
//
// See: https://auth0.com/docs/api/management/v2#!/Tickets/post_email_verification
func (tm *TicketManager) VerifyEmail(t *Ticket) (*Ticket, error) {
err := tm.m.post(tm.m.uri("tickets", "email-verification"), t)
return t, err
}
// Create a password change ticket for a user.
//
// See: https://auth0.com/docs/api/management/v2#!/Tickets/post_password_change
func (tm *TicketManager) ChangePassword(t *Ticket) (*Ticket, error) {
err := tm.m.post(tm.m.uri("tickets", "password-change"), t)
return t, err
}