@@ -130,16 +130,6 @@ type Meta struct {
130
130
URL * string `json:"url"`
131
131
}
132
132
133
- type ClientParams struct {
134
- Username string
135
- Password string
136
- AccountSid string
137
- Client client.BaseClient
138
- OrgClientCredentialProvider * OrgClientCredentialProvider
139
- ClientCredentialProvider * ClientCredentialProvider
140
- }
141
-
142
- // CredentialProvider for Oauth Applications
143
133
type CredentialProvider struct {
144
134
AuthType string
145
135
}
@@ -181,7 +171,7 @@ type ClientTokenManager struct {
181
171
Scope string
182
172
}
183
173
184
- func GetOrgAccessToken (manager OrgTokenManager , apiService * PreviewIamTemp. ApiService ) (* PreviewIamTemp.OauthV1Token , error ) {
174
+ func GetOrgAccessToken (manager OrgTokenManager ) (* PreviewIamTemp.OauthV1Token , error ) {
185
175
params := & PreviewIamTemp.CreateTokenParams {}
186
176
params .SetGrantType (manager .GrantType )
187
177
params .SetClientId (manager .ClientId )
@@ -192,15 +182,15 @@ func GetOrgAccessToken(manager OrgTokenManager, apiService *PreviewIamTemp.ApiSe
192
182
params .SetRefreshToken (manager .RefreshToken )
193
183
params .SetScope (manager .Scope )
194
184
195
- token , err := apiService .CreateToken (params )
185
+ token , err := PreviewIamTemp . NewApiService ( NewRestClient (). RequestHandler ) .CreateToken (params )
196
186
if err != nil {
197
187
return nil , fmt .Errorf ("failed to get access token: %w" , err )
198
188
}
199
189
200
190
return token , nil
201
191
}
202
192
203
- func GetClientAccessToken (manager ClientTokenManager , apiService * PreviewIamTemp. ApiService ) (* PreviewIamTemp.OauthV1Token , error ) {
193
+ func GetClientAccessToken (manager ClientTokenManager ) (* PreviewIamTemp.OauthV1Token , error ) {
204
194
params := & PreviewIamTemp.CreateTokenParams {}
205
195
params .SetGrantType (manager .GrantType )
206
196
params .SetClientId (manager .ClientId )
@@ -211,14 +201,23 @@ func GetClientAccessToken(manager ClientTokenManager, apiService *PreviewIamTemp
211
201
params .SetRefreshToken (manager .RefreshToken )
212
202
params .SetScope (manager .Scope )
213
203
214
- token , err := apiService .CreateToken (params )
204
+ token , err := PreviewIamTemp . NewApiService ( NewRestClient (). RequestHandler ) .CreateToken (params )
215
205
if err != nil {
216
206
return nil , fmt .Errorf ("failed to get access token: %w" , err )
217
207
}
218
208
219
209
return token , nil
220
210
}
221
211
212
+ type ClientParams struct {
213
+ Username string
214
+ Password string
215
+ AccountSid string
216
+ Client client.BaseClient
217
+ OrgClientCredentialProvider * OrgClientCredentialProvider
218
+ ClientCredentialProvider * ClientCredentialProvider
219
+ }
220
+
222
221
// NewRestClientWithParams provides an initialized Twilio RestClient with params.
223
222
func NewRestClientWithParams (params ClientParams ) * RestClient {
224
223
requestHandler := client .NewRequestHandler (params .Client )
@@ -257,19 +256,19 @@ func NewRestClientWithParams(params ClientParams) *RestClient {
257
256
RefreshToken : "" ,
258
257
Scope : "" }
259
258
260
- token , err := GetOrgAccessToken (orgTokenManager , NewRestClient (). PreviewIamToken )
259
+ token , err := GetOrgAccessToken (orgTokenManager )
261
260
//fmt.Println(*token.AccessToken)
262
261
if err != nil {
263
262
}
264
- fmt .Println (token )
263
+ fmt .Println (token . AccessToken )
265
264
266
265
defaultClient := & client.Client {
267
266
Credentials : client .NewCredentials ("" , "" ),
268
267
}
269
268
if params .AccountSid != "" {
270
269
defaultClient .SetAccountSid (params .AccountSid )
271
270
}
272
- defaultClient .SetBearerToken ("eyJhbGciOiJSUzI1NiIsImtpZCI6InVmQXhySkZ5VmNSNkdnQmZNQ29BTFoiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL2FwaS50d2lsaW8uY29tL3YyIiwiYXpwIjoiT1EwYmFkOWI1Yjc5ODEzNjhkOGI2NDFkNWFiY2MwOThjZCIsImlhdCI6MTczOTQ0OTIwMCwiZXhwIjoxNzM5NDUyODAwLCJpc3MiOiJodHRwczovL3ByZXZpZXctaWFtLnR3aWxpby5jb20iLCJzdWIiOiJPUTBiYWQ5YjViNzk4MTM2OGQ4YjY0MWQ1YWJjYzA5OGNkIiwiZ3R5IjoiY2xpZW50X2NyZWRlbnRpYWxzIiwiaHR0cDovL3R3aWxpby9hY3QiOnsic3ViIjoiQUM1NmM5YTA0ZDJlNjM5OTE1NWM3YzRhNTJmMDQ0YzEwNSJ9LCJodHRwOi8vdHdpbGlvL3R5cCI6InZuZC50d2lsaW8ub2F1dGguYXQrand0OyIsImh0dHA6Ly90d2lsaW8vc3ViIjoiT1EwYmFkOWI1Yjc5ODEzNjhkOGI2NDFkNWFiY2MwOThjZCIsImh0dHA6Ly90d2lsaW8vdmFsaWRyZWdpb25zIjoidXMxIn0.ColuyOS-CDSLmS0E16GU6GXHEt8Y5qxj4383S1r2j9YDI3swSKNfjpWvacevLJQBqxtBMZoawV7fyxZk-X0HmmlVJN_DUtwIY04u93BdM114chiKdL4rO49kxdzxdC6tViulWlFQzpvAg3hC1W-pgBIb8v48Z6SwpotZT3HM8VGVgEYPeFb3I6aQOpvNM9o1fNGFb4GWs6V78d9XvvjhvRsB58TfoFWEyfEwZZt-yWp__fmE-VaC5acnm3ATQ6TGInUiGzH6GqaDMtluj_TW0kefcawL7mJYjWFig9Mj27THk9ESa9H8JKm1-c0tJj0yVivp-UHN0ZfvcuDiHdhcEw " )
271
+ defaultClient .SetBearerToken ("" )
273
272
requestHandler = client .NewRequestHandler (defaultClient )
274
273
} else if params .ClientCredentialProvider != nil {
275
274
// get AccessToken
@@ -284,19 +283,19 @@ func NewRestClientWithParams(params ClientParams) *RestClient {
284
283
RefreshToken : "" ,
285
284
Scope : "" }
286
285
287
- token , err := GetClientAccessToken (clientTokenManager , NewRestClient (). PreviewIamToken )
286
+ token , err := GetClientAccessToken (clientTokenManager )
288
287
//fmt.Println(*token.AccessToken)
289
288
if err != nil {
290
289
}
291
- fmt .Println (token )
290
+ fmt .Println (token . AccessToken )
292
291
293
292
defaultClient := & client.Client {
294
293
Credentials : client .NewCredentials ("" , "" ),
295
294
}
296
295
if params .AccountSid != "" {
297
296
defaultClient .SetAccountSid (params .AccountSid )
298
297
}
299
- defaultClient .SetBearerToken ("eyJhbGciOiJSUzI1NiIsImtpZCI6InVmQXhySkZ5VmNSNkdnQmZNQ29BTFoiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL2FwaS50d2lsaW8uY29tL3YyIiwiYXpwIjoiT1EwYmFkOWI1Yjc5ODEzNjhkOGI2NDFkNWFiY2MwOThjZCIsImlhdCI6MTczOTQ0OTIwMCwiZXhwIjoxNzM5NDUyODAwLCJpc3MiOiJodHRwczovL3ByZXZpZXctaWFtLnR3aWxpby5jb20iLCJzdWIiOiJPUTBiYWQ5YjViNzk4MTM2OGQ4YjY0MWQ1YWJjYzA5OGNkIiwiZ3R5IjoiY2xpZW50X2NyZWRlbnRpYWxzIiwiaHR0cDovL3R3aWxpby9hY3QiOnsic3ViIjoiQUM1NmM5YTA0ZDJlNjM5OTE1NWM3YzRhNTJmMDQ0YzEwNSJ9LCJodHRwOi8vdHdpbGlvL3R5cCI6InZuZC50d2lsaW8ub2F1dGguYXQrand0OyIsImh0dHA6Ly90d2lsaW8vc3ViIjoiT1EwYmFkOWI1Yjc5ODEzNjhkOGI2NDFkNWFiY2MwOThjZCIsImh0dHA6Ly90d2lsaW8vdmFsaWRyZWdpb25zIjoidXMxIn0.ColuyOS-CDSLmS0E16GU6GXHEt8Y5qxj4383S1r2j9YDI3swSKNfjpWvacevLJQBqxtBMZoawV7fyxZk-X0HmmlVJN_DUtwIY04u93BdM114chiKdL4rO49kxdzxdC6tViulWlFQzpvAg3hC1W-pgBIb8v48Z6SwpotZT3HM8VGVgEYPeFb3I6aQOpvNM9o1fNGFb4GWs6V78d9XvvjhvRsB58TfoFWEyfEwZZt-yWp__fmE-VaC5acnm3ATQ6TGInUiGzH6GqaDMtluj_TW0kefcawL7mJYjWFig9Mj27THk9ESa9H8JKm1-c0tJj0yVivp-UHN0ZfvcuDiHdhcEw " )
298
+ defaultClient .SetBearerToken ("" )
300
299
requestHandler = client .NewRequestHandler (defaultClient )
301
300
}
302
301
@@ -355,30 +354,6 @@ func NewRestClientWithParams(params ClientParams) *RestClient {
355
354
return c
356
355
}
357
356
358
- func NewRestClientWithClientCredentials (params ClientCredentialProvider ) {
359
- // get AccessToken
360
- // set accessToken in client
361
- clientTokenManager := ClientTokenManager {
362
- GrantType : params .GrantType ,
363
- ClientId : params .ClientId ,
364
- ClientSecret : params .ClientSecret ,
365
- Code : "" ,
366
- RedirectUri : "" ,
367
- Audience : "" ,
368
- RefreshToken : "" ,
369
- Scope : "" }
370
-
371
- token , err := GetClientAccessToken (clientTokenManager , NewRestClient ().PreviewIamToken )
372
- fmt .Println (* token .AccessToken )
373
- if err != nil {
374
- }
375
-
376
- defaultClient := & client.Client {
377
- Credentials : client .NewCredentials ("" , "" ),
378
- }
379
- defaultClient .SetBearerToken (* token .AccessToken )
380
- }
381
-
382
357
// NewRestClient provides an initialized Twilio RestClient.
383
358
func NewRestClient () * RestClient {
384
359
return NewRestClientWithParams (ClientParams {})
0 commit comments