github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_o_auth.go (about) 1 2 /* 3 * Tyk Gateway API 4 * 5 * The Tyk Gateway API is the primary means for integrating your application with the Tyk API Gateway system. This API is very small, and has no granular permissions system. It is intended to be used purely for internal automation and integration. **Warning: Under no circumstances should outside parties be granted access to this API.** The Tyk Gateway API is capable of: * Managing session objects (key generation) * Managing and listing policies * Managing and listing API Definitions (only when not using the Dashboard) * Hot reloads / reloading a cluster configuration * OAuth client creation (only when not using the Dashboard) In order to use the Gateway API, you'll need to set the `secret` parameter in your tyk.conf file. The shared secret you set should then be sent along as a header with each Gateway API Request in order for it to be successful: ``` x-tyk-authorization: <your-secret> ``` <br/> <b>The Tyk Gateway API is subsumed by the Tyk Dashboard API in Pro installations.</b> 6 * 7 * API version: 5.5.0 8 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 9 */ 10 package swagger 11 12 import ( 13 "context" 14 "io/ioutil" 15 "net/http" 16 "net/url" 17 "strings" 18 "fmt" 19 "github.com/antihax/optional" 20 ) 21 22 // Linger please 23 var ( 24 _ context.Context 25 ) 26 27 type OAuthApiService service 28 /* 29 OAuthApiService Authorize client 30 With the OAuth flow you will need to create authorisation or access tokens for your clients, in order to do this, Tyk provides a private API endpoint for your application to generate these codes and redirect the end-user back to the API Client. 31 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 32 * @param responseType 33 * @param clientId 34 * @param redirectUri 35 * @param keyRules 36 @return interface{} 37 */ 38 func (a *OAuthApiService) AuthorizeClient(ctx context.Context, responseType string, clientId string, redirectUri string, keyRules string) (interface{}, *http.Response, error) { 39 var ( 40 localVarHttpMethod = strings.ToUpper("Post") 41 localVarPostBody interface{} 42 localVarFileName string 43 localVarFileBytes []byte 44 localVarReturnValue interface{} 45 ) 46 47 // create path and map variables 48 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/authorize-client/" 49 50 localVarHeaderParams := make(map[string]string) 51 localVarQueryParams := url.Values{} 52 localVarFormParams := url.Values{} 53 54 // to determine the Content-Type header 55 localVarHttpContentTypes := []string{"application/x-www-form-urlencoded"} 56 57 // set Content-Type header 58 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 59 if localVarHttpContentType != "" { 60 localVarHeaderParams["Content-Type"] = localVarHttpContentType 61 } 62 63 // to determine the Accept header 64 localVarHttpHeaderAccepts := []string{"application/json"} 65 66 // set Accept header 67 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 68 if localVarHttpHeaderAccept != "" { 69 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 70 } 71 localVarFormParams.Add("response_type", parameterToString(responseType, "")) 72 localVarFormParams.Add("client_id", parameterToString(clientId, "")) 73 localVarFormParams.Add("redirect_uri", parameterToString(redirectUri, "")) 74 localVarFormParams.Add("key_rules", parameterToString(keyRules, "")) 75 if ctx != nil { 76 // API Key Authentication 77 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 78 var key string 79 if auth.Prefix != "" { 80 key = auth.Prefix + " " + auth.Key 81 } else { 82 key = auth.Key 83 } 84 localVarHeaderParams["X-Tyk-Authorization"] = key 85 86 } 87 } 88 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 89 if err != nil { 90 return localVarReturnValue, nil, err 91 } 92 93 localVarHttpResponse, err := a.client.callAPI(r) 94 if err != nil || localVarHttpResponse == nil { 95 return localVarReturnValue, localVarHttpResponse, err 96 } 97 98 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 99 localVarHttpResponse.Body.Close() 100 if err != nil { 101 return localVarReturnValue, localVarHttpResponse, err 102 } 103 104 if localVarHttpResponse.StatusCode < 300 { 105 // If we succeed, return the data, otherwise pass on to decode error. 106 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 107 if err == nil { 108 return localVarReturnValue, localVarHttpResponse, err 109 } 110 } 111 112 if localVarHttpResponse.StatusCode >= 300 { 113 newErr := GenericSwaggerError{ 114 body: localVarBody, 115 error: localVarHttpResponse.Status, 116 } 117 if localVarHttpResponse.StatusCode == 200 { 118 var v interface{} 119 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 120 if err != nil { 121 newErr.error = err.Error() 122 return localVarReturnValue, localVarHttpResponse, newErr 123 } 124 newErr.model = v 125 return localVarReturnValue, localVarHttpResponse, newErr 126 } 127 return localVarReturnValue, localVarHttpResponse, newErr 128 } 129 130 return localVarReturnValue, localVarHttpResponse, nil 131 } 132 /* 133 OAuthApiService Create new OAuth client 134 Any OAuth keys must be generated with the help of a client ID. These need to be pre-registered with Tyk before they can be used (in a similar vein to how you would register your app with Twitter before attempting to ask user permissions using their API). <br/><br/> <h3>Creating OAuth clients with Access to Multiple APIs</h3> New from Tyk Gateway 2.6.0 is the ability to create OAuth clients with access to more than one API. If you provide the api_id it works the same as in previous releases. If you don't provide the api_id the request uses policy access rights and enumerates APIs from their setting in the newly created OAuth-client. 135 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 136 * @param optional nil or *OAuthApiCreateOAuthClientOpts - Optional Parameters: 137 * @param "Body" (optional.Interface of NewClientRequest) - 138 @return NewClientRequest 139 */ 140 141 type OAuthApiCreateOAuthClientOpts struct { 142 Body optional.Interface 143 } 144 145 func (a *OAuthApiService) CreateOAuthClient(ctx context.Context, localVarOptionals *OAuthApiCreateOAuthClientOpts) (NewClientRequest, *http.Response, error) { 146 var ( 147 localVarHttpMethod = strings.ToUpper("Post") 148 localVarPostBody interface{} 149 localVarFileName string 150 localVarFileBytes []byte 151 localVarReturnValue NewClientRequest 152 ) 153 154 // create path and map variables 155 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/create" 156 157 localVarHeaderParams := make(map[string]string) 158 localVarQueryParams := url.Values{} 159 localVarFormParams := url.Values{} 160 161 // to determine the Content-Type header 162 localVarHttpContentTypes := []string{"application/json"} 163 164 // set Content-Type header 165 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 166 if localVarHttpContentType != "" { 167 localVarHeaderParams["Content-Type"] = localVarHttpContentType 168 } 169 170 // to determine the Accept header 171 localVarHttpHeaderAccepts := []string{"application/json"} 172 173 // set Accept header 174 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 175 if localVarHttpHeaderAccept != "" { 176 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 177 } 178 // body params 179 if localVarOptionals != nil && localVarOptionals.Body.IsSet() { 180 181 localVarOptionalBody:= localVarOptionals.Body.Value() 182 localVarPostBody = &localVarOptionalBody 183 } 184 if ctx != nil { 185 // API Key Authentication 186 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 187 var key string 188 if auth.Prefix != "" { 189 key = auth.Prefix + " " + auth.Key 190 } else { 191 key = auth.Key 192 } 193 localVarHeaderParams["X-Tyk-Authorization"] = key 194 195 } 196 } 197 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 198 if err != nil { 199 return localVarReturnValue, nil, err 200 } 201 202 localVarHttpResponse, err := a.client.callAPI(r) 203 if err != nil || localVarHttpResponse == nil { 204 return localVarReturnValue, localVarHttpResponse, err 205 } 206 207 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 208 localVarHttpResponse.Body.Close() 209 if err != nil { 210 return localVarReturnValue, localVarHttpResponse, err 211 } 212 213 if localVarHttpResponse.StatusCode < 300 { 214 // If we succeed, return the data, otherwise pass on to decode error. 215 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 216 if err == nil { 217 return localVarReturnValue, localVarHttpResponse, err 218 } 219 } 220 221 if localVarHttpResponse.StatusCode >= 300 { 222 newErr := GenericSwaggerError{ 223 body: localVarBody, 224 error: localVarHttpResponse.Status, 225 } 226 if localVarHttpResponse.StatusCode == 200 { 227 var v NewClientRequest 228 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 229 if err != nil { 230 newErr.error = err.Error() 231 return localVarReturnValue, localVarHttpResponse, newErr 232 } 233 newErr.model = v 234 return localVarReturnValue, localVarHttpResponse, newErr 235 } 236 return localVarReturnValue, localVarHttpResponse, newErr 237 } 238 239 return localVarReturnValue, localVarHttpResponse, nil 240 } 241 /* 242 OAuthApiService Delete OAuth client 243 Please note that tokens issued with the client ID will still be valid until they expire. 244 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 245 * @param apiID The API ID 246 * @param keyName The Client ID 247 @return ApiModifyKeySuccess 248 */ 249 func (a *OAuthApiService) DeleteOAuthClient(ctx context.Context, apiID string, keyName string) (ApiModifyKeySuccess, *http.Response, error) { 250 var ( 251 localVarHttpMethod = strings.ToUpper("Delete") 252 localVarPostBody interface{} 253 localVarFileName string 254 localVarFileBytes []byte 255 localVarReturnValue ApiModifyKeySuccess 256 ) 257 258 // create path and map variables 259 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/{apiID}/{keyName}" 260 localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1) 261 localVarPath = strings.Replace(localVarPath, "{"+"keyName"+"}", fmt.Sprintf("%v", keyName), -1) 262 263 localVarHeaderParams := make(map[string]string) 264 localVarQueryParams := url.Values{} 265 localVarFormParams := url.Values{} 266 apiIDTxt, err := atoi(apiID) 267 if apiIDTxt < 1 { 268 return localVarReturnValue, nil, reportError("apiID must be greater than 1") 269 } 270 271 // to determine the Content-Type header 272 localVarHttpContentTypes := []string{} 273 274 // set Content-Type header 275 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 276 if localVarHttpContentType != "" { 277 localVarHeaderParams["Content-Type"] = localVarHttpContentType 278 } 279 280 // to determine the Accept header 281 localVarHttpHeaderAccepts := []string{"application/json"} 282 283 // set Accept header 284 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 285 if localVarHttpHeaderAccept != "" { 286 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 287 } 288 if ctx != nil { 289 // API Key Authentication 290 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 291 var key string 292 if auth.Prefix != "" { 293 key = auth.Prefix + " " + auth.Key 294 } else { 295 key = auth.Key 296 } 297 localVarHeaderParams["X-Tyk-Authorization"] = key 298 299 } 300 } 301 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 302 if err != nil { 303 return localVarReturnValue, nil, err 304 } 305 306 localVarHttpResponse, err := a.client.callAPI(r) 307 if err != nil || localVarHttpResponse == nil { 308 return localVarReturnValue, localVarHttpResponse, err 309 } 310 311 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 312 localVarHttpResponse.Body.Close() 313 if err != nil { 314 return localVarReturnValue, localVarHttpResponse, err 315 } 316 317 if localVarHttpResponse.StatusCode < 300 { 318 // If we succeed, return the data, otherwise pass on to decode error. 319 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 320 if err == nil { 321 return localVarReturnValue, localVarHttpResponse, err 322 } 323 } 324 325 if localVarHttpResponse.StatusCode >= 300 { 326 newErr := GenericSwaggerError{ 327 body: localVarBody, 328 error: localVarHttpResponse.Status, 329 } 330 if localVarHttpResponse.StatusCode == 200 { 331 var v ApiModifyKeySuccess 332 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 333 if err != nil { 334 newErr.error = err.Error() 335 return localVarReturnValue, localVarHttpResponse, newErr 336 } 337 newErr.model = v 338 return localVarReturnValue, localVarHttpResponse, newErr 339 } 340 return localVarReturnValue, localVarHttpResponse, newErr 341 } 342 343 return localVarReturnValue, localVarHttpResponse, nil 344 } 345 /* 346 OAuthApiService Get OAuth client 347 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 348 * @param apiID The API ID 349 * @param keyName The Client ID 350 @return NewClientRequest 351 */ 352 func (a *OAuthApiService) GetOAuthClient(ctx context.Context, apiID string, keyName string) (NewClientRequest, *http.Response, error) { 353 var ( 354 localVarHttpMethod = strings.ToUpper("Get") 355 localVarPostBody interface{} 356 localVarFileName string 357 localVarFileBytes []byte 358 localVarReturnValue NewClientRequest 359 ) 360 361 // create path and map variables 362 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/{apiID}/{keyName}" 363 localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1) 364 localVarPath = strings.Replace(localVarPath, "{"+"keyName"+"}", fmt.Sprintf("%v", keyName), -1) 365 366 localVarHeaderParams := make(map[string]string) 367 localVarQueryParams := url.Values{} 368 localVarFormParams := url.Values{} 369 apiIDTxt, err := atoi(apiID) 370 if apiIDTxt < 1 { 371 return localVarReturnValue, nil, reportError("apiID must be greater than 1") 372 } 373 374 // to determine the Content-Type header 375 localVarHttpContentTypes := []string{} 376 377 // set Content-Type header 378 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 379 if localVarHttpContentType != "" { 380 localVarHeaderParams["Content-Type"] = localVarHttpContentType 381 } 382 383 // to determine the Accept header 384 localVarHttpHeaderAccepts := []string{"application/json"} 385 386 // set Accept header 387 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 388 if localVarHttpHeaderAccept != "" { 389 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 390 } 391 if ctx != nil { 392 // API Key Authentication 393 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 394 var key string 395 if auth.Prefix != "" { 396 key = auth.Prefix + " " + auth.Key 397 } else { 398 key = auth.Key 399 } 400 localVarHeaderParams["X-Tyk-Authorization"] = key 401 402 } 403 } 404 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 405 if err != nil { 406 return localVarReturnValue, nil, err 407 } 408 409 localVarHttpResponse, err := a.client.callAPI(r) 410 if err != nil || localVarHttpResponse == nil { 411 return localVarReturnValue, localVarHttpResponse, err 412 } 413 414 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 415 localVarHttpResponse.Body.Close() 416 if err != nil { 417 return localVarReturnValue, localVarHttpResponse, err 418 } 419 420 if localVarHttpResponse.StatusCode < 300 { 421 // If we succeed, return the data, otherwise pass on to decode error. 422 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 423 if err == nil { 424 return localVarReturnValue, localVarHttpResponse, err 425 } 426 } 427 428 if localVarHttpResponse.StatusCode >= 300 { 429 newErr := GenericSwaggerError{ 430 body: localVarBody, 431 error: localVarHttpResponse.Status, 432 } 433 if localVarHttpResponse.StatusCode == 200 { 434 var v NewClientRequest 435 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 436 if err != nil { 437 newErr.error = err.Error() 438 return localVarReturnValue, localVarHttpResponse, newErr 439 } 440 newErr.model = v 441 return localVarReturnValue, localVarHttpResponse, newErr 442 } 443 return localVarReturnValue, localVarHttpResponse, newErr 444 } 445 446 return localVarReturnValue, localVarHttpResponse, nil 447 } 448 /* 449 OAuthApiService List tokens 450 This endpoint allows you to retrieve a list of all current tokens and their expiry date for a provided API ID and OAuth-client ID in the following format. This endpoint will work only for newly created tokens. <br/> <br/> You can control how long you want to store expired tokens in this list using `oauth_token_expired_retain_period` gateway option, which specifies retain period for expired tokens stored in Redis. By default expired token not get removed. See <a href=\"https://tyk.io/docs/configure/tyk-gateway-configuration-options/#a-name-oauth-token-expired-retain-period-a-oauth-token-expired-retain-period\" target=\"_blank\">here</a> for more details. 451 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 452 * @param apiID The API ID 453 * @param keyName The Client ID 454 @return []string 455 */ 456 func (a *OAuthApiService) GetOAuthClientTokens(ctx context.Context, apiID string, keyName string) ([]string, *http.Response, error) { 457 var ( 458 localVarHttpMethod = strings.ToUpper("Get") 459 localVarPostBody interface{} 460 localVarFileName string 461 localVarFileBytes []byte 462 localVarReturnValue []string 463 ) 464 465 // create path and map variables 466 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/{apiID}/{keyName}/tokens" 467 localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1) 468 localVarPath = strings.Replace(localVarPath, "{"+"keyName"+"}", fmt.Sprintf("%v", keyName), -1) 469 470 localVarHeaderParams := make(map[string]string) 471 localVarQueryParams := url.Values{} 472 localVarFormParams := url.Values{} 473 apiIDTxt, err := atoi(apiID) 474 if apiIDTxt < 1 { 475 return localVarReturnValue, nil, reportError("apiID must be greater than 1") 476 } 477 478 // to determine the Content-Type header 479 localVarHttpContentTypes := []string{} 480 481 // set Content-Type header 482 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 483 if localVarHttpContentType != "" { 484 localVarHeaderParams["Content-Type"] = localVarHttpContentType 485 } 486 487 // to determine the Accept header 488 localVarHttpHeaderAccepts := []string{"application/json"} 489 490 // set Accept header 491 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 492 if localVarHttpHeaderAccept != "" { 493 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 494 } 495 if ctx != nil { 496 // API Key Authentication 497 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 498 var key string 499 if auth.Prefix != "" { 500 key = auth.Prefix + " " + auth.Key 501 } else { 502 key = auth.Key 503 } 504 localVarHeaderParams["X-Tyk-Authorization"] = key 505 506 } 507 } 508 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 509 if err != nil { 510 return localVarReturnValue, nil, err 511 } 512 513 localVarHttpResponse, err := a.client.callAPI(r) 514 if err != nil || localVarHttpResponse == nil { 515 return localVarReturnValue, localVarHttpResponse, err 516 } 517 518 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 519 localVarHttpResponse.Body.Close() 520 if err != nil { 521 return localVarReturnValue, localVarHttpResponse, err 522 } 523 524 if localVarHttpResponse.StatusCode < 300 { 525 // If we succeed, return the data, otherwise pass on to decode error. 526 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 527 if err == nil { 528 return localVarReturnValue, localVarHttpResponse, err 529 } 530 } 531 532 if localVarHttpResponse.StatusCode >= 300 { 533 newErr := GenericSwaggerError{ 534 body: localVarBody, 535 error: localVarHttpResponse.Status, 536 } 537 if localVarHttpResponse.StatusCode == 200 { 538 var v []string 539 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 540 if err != nil { 541 newErr.error = err.Error() 542 return localVarReturnValue, localVarHttpResponse, newErr 543 } 544 newErr.model = v 545 return localVarReturnValue, localVarHttpResponse, newErr 546 } 547 return localVarReturnValue, localVarHttpResponse, newErr 548 } 549 550 return localVarReturnValue, localVarHttpResponse, nil 551 } 552 /* 553 OAuthApiService Invalidate OAuth refresh token 554 It is possible to invalidate refresh tokens in order to manage OAuth client access more robustly. 555 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 556 * @param apiId The API id 557 * @param keyName Refresh token 558 @return ApiModifyKeySuccess 559 */ 560 func (a *OAuthApiService) InvalidateOAuthRefresh(ctx context.Context, apiId string, keyName string) (ApiModifyKeySuccess, *http.Response, error) { 561 var ( 562 localVarHttpMethod = strings.ToUpper("Delete") 563 localVarPostBody interface{} 564 localVarFileName string 565 localVarFileBytes []byte 566 localVarReturnValue ApiModifyKeySuccess 567 ) 568 569 // create path and map variables 570 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/refresh/{keyName}" 571 localVarPath = strings.Replace(localVarPath, "{"+"keyName"+"}", fmt.Sprintf("%v", keyName), -1) 572 573 localVarHeaderParams := make(map[string]string) 574 localVarQueryParams := url.Values{} 575 localVarFormParams := url.Values{} 576 577 localVarQueryParams.Add("api_id", parameterToString(apiId, "")) 578 // to determine the Content-Type header 579 localVarHttpContentTypes := []string{} 580 581 // set Content-Type header 582 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 583 if localVarHttpContentType != "" { 584 localVarHeaderParams["Content-Type"] = localVarHttpContentType 585 } 586 587 // to determine the Accept header 588 localVarHttpHeaderAccepts := []string{"application/json"} 589 590 // set Accept header 591 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 592 if localVarHttpHeaderAccept != "" { 593 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 594 } 595 if ctx != nil { 596 // API Key Authentication 597 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 598 var key string 599 if auth.Prefix != "" { 600 key = auth.Prefix + " " + auth.Key 601 } else { 602 key = auth.Key 603 } 604 localVarHeaderParams["X-Tyk-Authorization"] = key 605 606 } 607 } 608 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 609 if err != nil { 610 return localVarReturnValue, nil, err 611 } 612 613 localVarHttpResponse, err := a.client.callAPI(r) 614 if err != nil || localVarHttpResponse == nil { 615 return localVarReturnValue, localVarHttpResponse, err 616 } 617 618 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 619 localVarHttpResponse.Body.Close() 620 if err != nil { 621 return localVarReturnValue, localVarHttpResponse, err 622 } 623 624 if localVarHttpResponse.StatusCode < 300 { 625 // If we succeed, return the data, otherwise pass on to decode error. 626 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 627 if err == nil { 628 return localVarReturnValue, localVarHttpResponse, err 629 } 630 } 631 632 if localVarHttpResponse.StatusCode >= 300 { 633 newErr := GenericSwaggerError{ 634 body: localVarBody, 635 error: localVarHttpResponse.Status, 636 } 637 if localVarHttpResponse.StatusCode == 200 { 638 var v ApiModifyKeySuccess 639 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 640 if err != nil { 641 newErr.error = err.Error() 642 return localVarReturnValue, localVarHttpResponse, newErr 643 } 644 newErr.model = v 645 return localVarReturnValue, localVarHttpResponse, newErr 646 } 647 return localVarReturnValue, localVarHttpResponse, newErr 648 } 649 650 return localVarReturnValue, localVarHttpResponse, nil 651 } 652 /* 653 OAuthApiService List oAuth clients 654 OAuth Clients are organised by API ID, and therefore are queried as such. 655 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 656 * @param apiID The API ID 657 @return []NewClientRequest 658 */ 659 func (a *OAuthApiService) ListOAuthClients(ctx context.Context, apiID string) ([]NewClientRequest, *http.Response, error) { 660 var ( 661 localVarHttpMethod = strings.ToUpper("Get") 662 localVarPostBody interface{} 663 localVarFileName string 664 localVarFileBytes []byte 665 localVarReturnValue []NewClientRequest 666 ) 667 668 // create path and map variables 669 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/{apiID}" 670 localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1) 671 672 localVarHeaderParams := make(map[string]string) 673 localVarQueryParams := url.Values{} 674 localVarFormParams := url.Values{} 675 676 // to determine the Content-Type header 677 localVarHttpContentTypes := []string{} 678 679 // set Content-Type header 680 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 681 if localVarHttpContentType != "" { 682 localVarHeaderParams["Content-Type"] = localVarHttpContentType 683 } 684 685 // to determine the Accept header 686 localVarHttpHeaderAccepts := []string{"application/json"} 687 688 // set Accept header 689 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 690 if localVarHttpHeaderAccept != "" { 691 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 692 } 693 if ctx != nil { 694 // API Key Authentication 695 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 696 var key string 697 if auth.Prefix != "" { 698 key = auth.Prefix + " " + auth.Key 699 } else { 700 key = auth.Key 701 } 702 localVarHeaderParams["X-Tyk-Authorization"] = key 703 704 } 705 } 706 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 707 if err != nil { 708 return localVarReturnValue, nil, err 709 } 710 711 localVarHttpResponse, err := a.client.callAPI(r) 712 if err != nil || localVarHttpResponse == nil { 713 return localVarReturnValue, localVarHttpResponse, err 714 } 715 716 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 717 localVarHttpResponse.Body.Close() 718 if err != nil { 719 return localVarReturnValue, localVarHttpResponse, err 720 } 721 722 if localVarHttpResponse.StatusCode < 300 { 723 // If we succeed, return the data, otherwise pass on to decode error. 724 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 725 if err == nil { 726 return localVarReturnValue, localVarHttpResponse, err 727 } 728 } 729 730 if localVarHttpResponse.StatusCode >= 300 { 731 newErr := GenericSwaggerError{ 732 body: localVarBody, 733 error: localVarHttpResponse.Status, 734 } 735 if localVarHttpResponse.StatusCode == 200 { 736 var v []NewClientRequest 737 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 738 if err != nil { 739 newErr.error = err.Error() 740 return localVarReturnValue, localVarHttpResponse, newErr 741 } 742 newErr.model = v 743 return localVarReturnValue, localVarHttpResponse, newErr 744 } 745 return localVarReturnValue, localVarHttpResponse, newErr 746 } 747 748 return localVarReturnValue, localVarHttpResponse, nil 749 } 750 /* 751 OAuthApiService revoke all client's tokens 752 revoke all the tokens for a given oauth client 753 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 754 * @param clientId 755 * @param clientSecret 756 757 */ 758 func (a *OAuthApiService) RevokeAllTokens(ctx context.Context, clientId string, clientSecret string) (*http.Response, error) { 759 var ( 760 localVarHttpMethod = strings.ToUpper("Post") 761 localVarPostBody interface{} 762 localVarFileName string 763 localVarFileBytes []byte 764 765 ) 766 767 // create path and map variables 768 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/revoke_all" 769 770 localVarHeaderParams := make(map[string]string) 771 localVarQueryParams := url.Values{} 772 localVarFormParams := url.Values{} 773 774 // to determine the Content-Type header 775 localVarHttpContentTypes := []string{"application/x-www-form-urlencoded"} 776 777 // set Content-Type header 778 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 779 if localVarHttpContentType != "" { 780 localVarHeaderParams["Content-Type"] = localVarHttpContentType 781 } 782 783 // to determine the Accept header 784 localVarHttpHeaderAccepts := []string{} 785 786 // set Accept header 787 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 788 if localVarHttpHeaderAccept != "" { 789 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 790 } 791 localVarFormParams.Add("client_id", parameterToString(clientId, "")) 792 localVarFormParams.Add("client_secret", parameterToString(clientSecret, "")) 793 if ctx != nil { 794 // API Key Authentication 795 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 796 var key string 797 if auth.Prefix != "" { 798 key = auth.Prefix + " " + auth.Key 799 } else { 800 key = auth.Key 801 } 802 localVarHeaderParams["X-Tyk-Authorization"] = key 803 804 } 805 } 806 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 807 if err != nil { 808 return nil, err 809 } 810 811 localVarHttpResponse, err := a.client.callAPI(r) 812 if err != nil || localVarHttpResponse == nil { 813 return localVarHttpResponse, err 814 } 815 816 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 817 localVarHttpResponse.Body.Close() 818 if err != nil { 819 return localVarHttpResponse, err 820 } 821 822 823 if localVarHttpResponse.StatusCode >= 300 { 824 newErr := GenericSwaggerError{ 825 body: localVarBody, 826 error: localVarHttpResponse.Status, 827 } 828 return localVarHttpResponse, newErr 829 } 830 831 return localVarHttpResponse, nil 832 } 833 /* 834 OAuthApiService revoke token 835 revoke a single token 836 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 837 * @param token 838 * @param clientId 839 * @param tokenTypeHint 840 841 */ 842 func (a *OAuthApiService) RevokeSingleToken(ctx context.Context, token string, clientId string, tokenTypeHint string) (*http.Response, error) { 843 var ( 844 localVarHttpMethod = strings.ToUpper("Post") 845 localVarPostBody interface{} 846 localVarFileName string 847 localVarFileBytes []byte 848 849 ) 850 851 // create path and map variables 852 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/revoke" 853 854 localVarHeaderParams := make(map[string]string) 855 localVarQueryParams := url.Values{} 856 localVarFormParams := url.Values{} 857 858 // to determine the Content-Type header 859 localVarHttpContentTypes := []string{"application/x-www-form-urlencoded"} 860 861 // set Content-Type header 862 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 863 if localVarHttpContentType != "" { 864 localVarHeaderParams["Content-Type"] = localVarHttpContentType 865 } 866 867 // to determine the Accept header 868 localVarHttpHeaderAccepts := []string{} 869 870 // set Accept header 871 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 872 if localVarHttpHeaderAccept != "" { 873 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 874 } 875 localVarFormParams.Add("token", parameterToString(token, "")) 876 localVarFormParams.Add("client_id", parameterToString(clientId, "")) 877 localVarFormParams.Add("token_type_hint", parameterToString(tokenTypeHint, "")) 878 if ctx != nil { 879 // API Key Authentication 880 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 881 var key string 882 if auth.Prefix != "" { 883 key = auth.Prefix + " " + auth.Key 884 } else { 885 key = auth.Key 886 } 887 localVarHeaderParams["X-Tyk-Authorization"] = key 888 889 } 890 } 891 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 892 if err != nil { 893 return nil, err 894 } 895 896 localVarHttpResponse, err := a.client.callAPI(r) 897 if err != nil || localVarHttpResponse == nil { 898 return localVarHttpResponse, err 899 } 900 901 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 902 localVarHttpResponse.Body.Close() 903 if err != nil { 904 return localVarHttpResponse, err 905 } 906 907 908 if localVarHttpResponse.StatusCode >= 300 { 909 newErr := GenericSwaggerError{ 910 body: localVarBody, 911 error: localVarHttpResponse.Status, 912 } 913 return localVarHttpResponse, newErr 914 } 915 916 return localVarHttpResponse, nil 917 } 918 /* 919 OAuthApiService Update OAuth metadata and Policy ID 920 Allows you to update the metadata and Policy ID for an OAuth client. 921 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 922 * @param apiID The API ID 923 @return []NewClientRequest 924 */ 925 func (a *OAuthApiService) UpdateoAuthClient(ctx context.Context, apiID string) ([]NewClientRequest, *http.Response, error) { 926 var ( 927 localVarHttpMethod = strings.ToUpper("Put") 928 localVarPostBody interface{} 929 localVarFileName string 930 localVarFileBytes []byte 931 localVarReturnValue []NewClientRequest 932 ) 933 934 // create path and map variables 935 localVarPath := a.client.cfg.BasePath + "/tyk/oauth/clients/{apiID}" 936 localVarPath = strings.Replace(localVarPath, "{"+"apiID"+"}", fmt.Sprintf("%v", apiID), -1) 937 938 localVarHeaderParams := make(map[string]string) 939 localVarQueryParams := url.Values{} 940 localVarFormParams := url.Values{} 941 942 // to determine the Content-Type header 943 localVarHttpContentTypes := []string{} 944 945 // set Content-Type header 946 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 947 if localVarHttpContentType != "" { 948 localVarHeaderParams["Content-Type"] = localVarHttpContentType 949 } 950 951 // to determine the Accept header 952 localVarHttpHeaderAccepts := []string{"application/json"} 953 954 // set Accept header 955 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 956 if localVarHttpHeaderAccept != "" { 957 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 958 } 959 if ctx != nil { 960 // API Key Authentication 961 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 962 var key string 963 if auth.Prefix != "" { 964 key = auth.Prefix + " " + auth.Key 965 } else { 966 key = auth.Key 967 } 968 localVarHeaderParams["X-Tyk-Authorization"] = key 969 970 } 971 } 972 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 973 if err != nil { 974 return localVarReturnValue, nil, err 975 } 976 977 localVarHttpResponse, err := a.client.callAPI(r) 978 if err != nil || localVarHttpResponse == nil { 979 return localVarReturnValue, localVarHttpResponse, err 980 } 981 982 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 983 localVarHttpResponse.Body.Close() 984 if err != nil { 985 return localVarReturnValue, localVarHttpResponse, err 986 } 987 988 if localVarHttpResponse.StatusCode < 300 { 989 // If we succeed, return the data, otherwise pass on to decode error. 990 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 991 if err == nil { 992 return localVarReturnValue, localVarHttpResponse, err 993 } 994 } 995 996 if localVarHttpResponse.StatusCode >= 300 { 997 newErr := GenericSwaggerError{ 998 body: localVarBody, 999 error: localVarHttpResponse.Status, 1000 } 1001 if localVarHttpResponse.StatusCode == 200 { 1002 var v []NewClientRequest 1003 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 1004 if err != nil { 1005 newErr.error = err.Error() 1006 return localVarReturnValue, localVarHttpResponse, newErr 1007 } 1008 newErr.model = v 1009 return localVarReturnValue, localVarHttpResponse, newErr 1010 } 1011 return localVarReturnValue, localVarHttpResponse, newErr 1012 } 1013 1014 return localVarReturnValue, localVarHttpResponse, nil 1015 }