-
Notifications
You must be signed in to change notification settings - Fork 19
/
sessions.go
63 lines (52 loc) · 1.54 KB
/
sessions.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
package clerk
import "fmt"
type SessionsService service
type Session struct {
Object string `json:"object"`
ID string `json:"id"`
ClientID string `json:"client_id"`
UserID string `json:"user_id"`
Status string `json:"status"`
LastActiveAt int64 `json:"last_active_at"`
ExpireAt int64 `json:"expire_at"`
AbandonAt int64 `json:"abandon_at"`
}
func (s *SessionsService) ListAll() ([]Session, error) {
sessionsUrl := "sessions"
req, _ := s.client.NewRequest("GET", sessionsUrl)
var sessions []Session
_, err := s.client.Do(req, &sessions)
if err != nil {
return nil, err
}
return sessions, nil
}
func (s *SessionsService) Read(sessionId string) (*Session, error) {
sessionUrl := fmt.Sprintf("%s/%s", SessionsUrl, sessionId)
req, _ := s.client.NewRequest("GET", sessionUrl)
var session Session
_, err := s.client.Do(req, &session)
if err != nil {
return nil, err
}
return &session, nil
}
func (s *SessionsService) Revoke(sessionId string) (*Session, error) {
sessionUrl := fmt.Sprintf("%s/%s/revoke", SessionsUrl, sessionId)
req, _ := s.client.NewRequest("POST", sessionUrl)
var session Session
_, err := s.client.Do(req, &session)
if err != nil {
return nil, err
}
return &session, nil
}
func (s *SessionsService) Verify(sessionId, token string) (*Session, error) {
verifyUrl := fmt.Sprintf("%s/%s/verify", SessionsUrl, sessionId)
var sessionResponse Session
err := doVerify(s.client, verifyUrl, token, &sessionResponse)
if err != nil {
return nil, err
}
return &sessionResponse, nil
}