-
Notifications
You must be signed in to change notification settings - Fork 23
/
token.go
51 lines (43 loc) · 1.6 KB
/
token.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
package plivo
type TokenService struct {
client *Client
}
type TokenCreateParams struct {
// Required parameters.
Iss string `json:"iss,omitempty" url:"iss,omitempty"`
// Optional parameters.
Exp int64 `json:"exp,omitempty" url:"Exp,omitempty"`
Nbf int64 `json:"nbf,omitempty" url:"Nbf,omitempty"`
IncomingAllow interface{} `json:"incoming_allow,omitempty" url:"incoming_allow,omitempty"`
OutgoingAllow interface{} `json:"outgoing_allow,omitempty" url:"outgoing_allow,omitempty"`
Per interface{} `json:"per,omitempty" url:"per,omitempty"`
App string `json:"app,omitempty" url:"App,omitempty"`
Sub string `json:"sub,omitempty" url:"Sub,omitempty"`
}
// Stores response for creating a token.
type TokenCreateResponse struct {
Token string `json:"token" url:"token"`
ApiID string `json:"api_id" url:"api_id"`
}
func (service *TokenService) Create(params TokenCreateParams) (response *TokenCreateResponse, err error) {
if params.IncomingAllow != nil || params.OutgoingAllow != nil {
voicemap := make(map[string]interface{})
if params.IncomingAllow != nil {
voicemap["incoming_allow"] = params.IncomingAllow
}
if params.OutgoingAllow != nil {
voicemap["outgoing_allow"] = params.OutgoingAllow
}
if len(voicemap) > 0 {
permissionsMap := map[string]interface{}{"voice": voicemap}
params.Per = permissionsMap
}
}
req, err := service.client.NewRequest("POST", params, "JWT/Token")
if err != nil {
return
}
response = &TokenCreateResponse{}
err = service.client.ExecuteRequest(req, response, isVoiceRequest())
return
}