-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtoken.go
122 lines (111 loc) · 3.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Oauth
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package openapi
import (
"encoding/json"
"net/url"
)
// Optional parameters for the method 'CreateToken'
type CreateTokenParams struct {
// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token.
GrantType *string `json:"GrantType,omitempty"`
// A 34 character string that uniquely identifies this OAuth App.
ClientId *string `json:"ClientId,omitempty"`
// The credential for confidential OAuth App.
ClientSecret *string `json:"ClientSecret,omitempty"`
// JWT token related to the authorization code grant type.
Code *string `json:"Code,omitempty"`
// The redirect uri
RedirectUri *string `json:"RedirectUri,omitempty"`
// The targeted audience uri
Audience *string `json:"Audience,omitempty"`
// JWT token related to refresh access token.
RefreshToken *string `json:"RefreshToken,omitempty"`
// The scope of token
Scope *string `json:"Scope,omitempty"`
}
func (params *CreateTokenParams) SetGrantType(GrantType string) *CreateTokenParams {
params.GrantType = &GrantType
return params
}
func (params *CreateTokenParams) SetClientId(ClientId string) *CreateTokenParams {
params.ClientId = &ClientId
return params
}
func (params *CreateTokenParams) SetClientSecret(ClientSecret string) *CreateTokenParams {
params.ClientSecret = &ClientSecret
return params
}
func (params *CreateTokenParams) SetCode(Code string) *CreateTokenParams {
params.Code = &Code
return params
}
func (params *CreateTokenParams) SetRedirectUri(RedirectUri string) *CreateTokenParams {
params.RedirectUri = &RedirectUri
return params
}
func (params *CreateTokenParams) SetAudience(Audience string) *CreateTokenParams {
params.Audience = &Audience
return params
}
func (params *CreateTokenParams) SetRefreshToken(RefreshToken string) *CreateTokenParams {
params.RefreshToken = &RefreshToken
return params
}
func (params *CreateTokenParams) SetScope(Scope string) *CreateTokenParams {
params.Scope = &Scope
return params
}
// Issues a new Access token (optionally identity_token & refresh_token) in exchange of Oauth grant
func (c *ApiService) CreateToken(params *CreateTokenParams) (*OauthV1Token, error) {
path := "/v1/token"
data := url.Values{}
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}
if params != nil && params.GrantType != nil {
data.Set("GrantType", *params.GrantType)
}
if params != nil && params.ClientId != nil {
data.Set("ClientId", *params.ClientId)
}
if params != nil && params.ClientSecret != nil {
data.Set("ClientSecret", *params.ClientSecret)
}
if params != nil && params.Code != nil {
data.Set("Code", *params.Code)
}
if params != nil && params.RedirectUri != nil {
data.Set("RedirectUri", *params.RedirectUri)
}
if params != nil && params.Audience != nil {
data.Set("Audience", *params.Audience)
}
if params != nil && params.RefreshToken != nil {
data.Set("RefreshToken", *params.RefreshToken)
}
if params != nil && params.Scope != nil {
data.Set("Scope", *params.Scope)
}
resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &OauthV1Token{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, err
}