-
Notifications
You must be signed in to change notification settings - Fork 19
/
impersonation_tokens.go
47 lines (39 loc) · 1.4 KB
/
impersonation_tokens.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
package clerk
import (
"fmt"
"net/http"
)
type ImpersonationTokenService service
type ImpersonationTokenRespose struct {
Object string `json:"object"`
ID string `json:"id"`
SubjectID string `json:"subject_id"`
ActorID string `json:"actor_id"`
Token string `json:"token,omitempty"`
Status string `json:"status"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
type CreateImpersonationTokenParams struct {
SubjectID string `json:"subject_id"`
ActorID string `json:"actor_id"`
ExpiresInSeconds *int `json:"expires_in_seconds"`
}
func (s *ImpersonationTokenService) Create(params CreateImpersonationTokenParams) (*ImpersonationTokenRespose, error) {
req, _ := s.client.NewRequest(http.MethodPost, ImpersonationTokensUrl, ¶ms)
var impersonationTokenResponse ImpersonationTokenRespose
_, err := s.client.Do(req, &impersonationTokenResponse)
if err != nil {
return nil, err
}
return &impersonationTokenResponse, nil
}
func (s *ImpersonationTokenService) Revoke(impersonationTokenID string) (*ImpersonationTokenRespose, error) {
req, _ := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s/%s/revoke", ImpersonationTokensUrl, impersonationTokenID))
var impersonationTokenResponse ImpersonationTokenRespose
_, err := s.client.Do(req, &impersonationTokenResponse)
if err != nil {
return nil, err
}
return &impersonationTokenResponse, nil
}