From 17993b98107335548320d76bacfdff304725a85c Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Wed, 19 Mar 2025 23:25:51 +0530 Subject: [PATCH 1/2] feat: oauth feature --- client/client.go | 89 ++++++++++++- oauth/token_auth.go | 62 +++++++++ oauth/token_manager.go | 52 ++++++++ rest/preview_iam/v1/README.md | 94 ++++++++++++++ rest/preview_iam/v1/api_service.go | 35 +++++ rest/preview_iam/v1/authorize.go | 94 ++++++++++++++ rest/preview_iam/v1/docs/JsonPatch.md | 13 ++ rest/preview_iam/v1/docs/OauthV1Authorize.md | 11 ++ rest/preview_iam/v1/docs/OauthV1Token.md | 15 +++ .../v1/docs/PublicApiAccountResponse.md | 15 +++ .../v1/docs/PublicApiAccountResponsePage.md | 12 ++ .../docs/PublicApiAccountResponsePageMeta.md | 17 +++ .../v1/docs/PublicApiCreateAccountRequest.md | 12 ++ .../v1/docs/PublicApiCreateAccountResponse.md | 11 ++ .../PublicApiCreateRoleAssignmentRequest.md | 13 ++ ...blicApiCreateRoleAssignmentResponsePage.md | 12 ++ .../docs/PublicApiRoleAssignmentResponse.md | 14 ++ rest/preview_iam/v1/docs/ScimEmailAddress.md | 13 ++ rest/preview_iam/v1/docs/ScimError.md | 16 +++ rest/preview_iam/v1/docs/ScimMeta.md | 14 ++ rest/preview_iam/v1/docs/ScimName.md | 12 ++ .../preview_iam/v1/docs/ScimPatchOperation.md | 13 ++ rest/preview_iam/v1/docs/ScimPatchRequest.md | 12 ++ rest/preview_iam/v1/docs/ScimResourceTypes.md | 11 ++ .../v1/docs/ScimResourceTypesResources.md | 14 ++ rest/preview_iam/v1/docs/ScimUser.md | 21 +++ rest/preview_iam/v1/docs/ScimUserPage.md | 13 ++ .../v1/docs/TwilioServiceErrorResponse.md | 14 ++ rest/preview_iam/v1/model_json_patch.go | 22 ++++ .../v1/model_oauth_v1_authorize.go | 21 +++ rest/preview_iam/v1/model_oauth_v1_token.go | 28 ++++ .../v1/model_public_api_account_response.go | 33 +++++ .../model_public_api_account_response_page.go | 22 ++++ ...l_public_api_account_response_page_meta.go | 26 ++++ ...model_public_api_create_account_request.go | 23 ++++ ...odel_public_api_create_account_response.go | 21 +++ ...blic_api_create_role_assignment_request.go | 25 ++++ ...pi_create_role_assignment_response_page.go | 22 ++++ ...del_public_api_role_assignment_response.go | 27 ++++ .../v1/model_scim_email_address.go | 25 ++++ rest/preview_iam/v1/model_scim_error.go | 31 +++++ rest/preview_iam/v1/model_scim_meta.go | 31 +++++ rest/preview_iam/v1/model_scim_name.go | 23 ++++ .../v1/model_scim_patch_operation.go | 23 ++++ .../v1/model_scim_patch_request.go | 21 +++ .../v1/model_scim_resource_types.go | 20 +++ .../v1/model_scim_resource_types_resources.go | 27 ++++ rest/preview_iam/v1/model_scim_user.go | 39 ++++++ rest/preview_iam/v1/model_scim_user_page.go | 22 ++++ .../v1/model_twilio_service_error_response.go | 27 ++++ rest/preview_iam/v1/token.go | 121 ++++++++++++++++++ test.go | 1 + twilio.go | 28 +++- 53 files changed, 1426 insertions(+), 7 deletions(-) create mode 100644 oauth/token_auth.go create mode 100644 oauth/token_manager.go create mode 100644 rest/preview_iam/v1/README.md create mode 100644 rest/preview_iam/v1/api_service.go create mode 100644 rest/preview_iam/v1/authorize.go create mode 100644 rest/preview_iam/v1/docs/JsonPatch.md create mode 100644 rest/preview_iam/v1/docs/OauthV1Authorize.md create mode 100644 rest/preview_iam/v1/docs/OauthV1Token.md create mode 100644 rest/preview_iam/v1/docs/PublicApiAccountResponse.md create mode 100644 rest/preview_iam/v1/docs/PublicApiAccountResponsePage.md create mode 100644 rest/preview_iam/v1/docs/PublicApiAccountResponsePageMeta.md create mode 100644 rest/preview_iam/v1/docs/PublicApiCreateAccountRequest.md create mode 100644 rest/preview_iam/v1/docs/PublicApiCreateAccountResponse.md create mode 100644 rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentRequest.md create mode 100644 rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentResponsePage.md create mode 100644 rest/preview_iam/v1/docs/PublicApiRoleAssignmentResponse.md create mode 100644 rest/preview_iam/v1/docs/ScimEmailAddress.md create mode 100644 rest/preview_iam/v1/docs/ScimError.md create mode 100644 rest/preview_iam/v1/docs/ScimMeta.md create mode 100644 rest/preview_iam/v1/docs/ScimName.md create mode 100644 rest/preview_iam/v1/docs/ScimPatchOperation.md create mode 100644 rest/preview_iam/v1/docs/ScimPatchRequest.md create mode 100644 rest/preview_iam/v1/docs/ScimResourceTypes.md create mode 100644 rest/preview_iam/v1/docs/ScimResourceTypesResources.md create mode 100644 rest/preview_iam/v1/docs/ScimUser.md create mode 100644 rest/preview_iam/v1/docs/ScimUserPage.md create mode 100644 rest/preview_iam/v1/docs/TwilioServiceErrorResponse.md create mode 100644 rest/preview_iam/v1/model_json_patch.go create mode 100644 rest/preview_iam/v1/model_oauth_v1_authorize.go create mode 100644 rest/preview_iam/v1/model_oauth_v1_token.go create mode 100644 rest/preview_iam/v1/model_public_api_account_response.go create mode 100644 rest/preview_iam/v1/model_public_api_account_response_page.go create mode 100644 rest/preview_iam/v1/model_public_api_account_response_page_meta.go create mode 100644 rest/preview_iam/v1/model_public_api_create_account_request.go create mode 100644 rest/preview_iam/v1/model_public_api_create_account_response.go create mode 100644 rest/preview_iam/v1/model_public_api_create_role_assignment_request.go create mode 100644 rest/preview_iam/v1/model_public_api_create_role_assignment_response_page.go create mode 100644 rest/preview_iam/v1/model_public_api_role_assignment_response.go create mode 100644 rest/preview_iam/v1/model_scim_email_address.go create mode 100644 rest/preview_iam/v1/model_scim_error.go create mode 100644 rest/preview_iam/v1/model_scim_meta.go create mode 100644 rest/preview_iam/v1/model_scim_name.go create mode 100644 rest/preview_iam/v1/model_scim_patch_operation.go create mode 100644 rest/preview_iam/v1/model_scim_patch_request.go create mode 100644 rest/preview_iam/v1/model_scim_resource_types.go create mode 100644 rest/preview_iam/v1/model_scim_resource_types_resources.go create mode 100644 rest/preview_iam/v1/model_scim_user.go create mode 100644 rest/preview_iam/v1/model_scim_user_page.go create mode 100644 rest/preview_iam/v1/model_twilio_service_error_response.go create mode 100644 rest/preview_iam/v1/token.go create mode 100644 test.go diff --git a/client/client.go b/client/client.go index e1cab41de..a058f65e2 100644 --- a/client/client.go +++ b/client/client.go @@ -13,8 +13,12 @@ import ( "strings" "time" + "github.com/golang-jwt/jwt" + "github.com/twilio/twilio-go/oauth" + "github.com/pkg/errors" "github.com/twilio/twilio-go/client/form" + preview_iam "github.com/twilio/twilio-go/rest/preview_iam/v1" ) var alphanumericRegex *regexp.Regexp @@ -27,8 +31,34 @@ func init() { // Credentials store user authentication credentials. type Credentials struct { - Username string - Password string + Username string + Password string + ClientCredentials *ClientCredentials +} + +type ClientCredentials struct { + GrantType string + ClientId string + ClientSecret string + RequestHandler RequestHandler +} + +func NewClientCredentials(grantType, clientId, clientSecret string, handler RequestHandler) *ClientCredentials { + return &ClientCredentials{GrantType: grantType, ClientId: clientId, ClientSecret: clientSecret, RequestHandler: handler} +} + +func (c *ClientCredentials) GetAccessToken() (string, error) { + tokenManager := &oauth.TokenManager{ + GrantType: c.GrantType, + ClientId: c.ClientId, + ClientSecret: c.ClientSecret, + Code: "", + Audience: "", + RefreshToken: "", + Scope: "", + } + tokenAuth := oauth.NewTokenAuthInitializer("", tokenManager) + return tokenAuth.FetchToken(c.RequestHandler) } func NewCredentials(username string, password string) *Credentials { @@ -41,6 +71,7 @@ type Client struct { HTTPClient *http.Client accountSid string UserAgentExtensions []string + ClientCredentials *ClientCredentials } // default http Client should not follow redirects and return the most recent response. @@ -65,6 +96,10 @@ func (c *Client) SetTimeout(timeout time.Duration) { c.HTTPClient.Timeout = timeout } +func (c *Client) SetClientCredentials(clientCredentials *ClientCredentials) { + c.ClientCredentials = clientCredentials +} + func extractContentTypeHeader(headers map[string]interface{}) (cType string) { headerType, ok := headers["Content-Type"] if !ok { @@ -186,6 +221,14 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values, if len(c.UserAgentExtensions) > 0 { userAgent += " " + strings.Join(c.UserAgentExtensions, " ") } + if c.ClientCredentials != nil { + token, err := c.ClientCredentials.GetAccessToken() + if err != nil { + req.Header.Add("Authorization", "Bearer "+token) + } + } else if c.Username != "" { + req.SetBasicAuth(c.basicAuth()) + } req.Header.Add("User-Agent", userAgent) @@ -204,3 +247,45 @@ func (c *Client) SetAccountSid(sid string) { func (c *Client) AccountSid() string { return c.accountSid } + +func GetAccessToken(grantType, clientId, clientSecret, code, redirectUri, audience, refreshToken, scope string, c RequestHandler) (string, error) { + params := &preview_iam.CreateTokenParams{} + params.SetGrantType(grantType). + SetClientId(clientId). + SetClientSecret(clientSecret). + SetCode(code). + SetRedirectUri(redirectUri). + SetAudience(audience). + SetRefreshToken(refreshToken). + SetScope(scope) + + token, err := preview_iam.NewApiService(&c).CreateToken(params) + if err != nil { + return "", err + } + + if token.AccessToken == nil { + return "", fmt.Errorf("access token is nil") + } + + return *token.AccessToken, nil +} + +func TokenExpired(tokenString string) bool { + // Parse the token without validating the signature + token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{}) + if err != nil { + return true // Consider token expired if there's an error parsing it + } + + // Extract the claims + if claims, ok := token.Claims.(jwt.MapClaims); ok { + // Get the expiration time + if exp, ok := claims["exp"].(float64); ok { + // Check if the token has expired + expirationTime := time.Unix(int64(exp), 0) + return time.Now().After(expirationTime) + } + } + return true // Cons +} diff --git a/oauth/token_auth.go b/oauth/token_auth.go new file mode 100644 index 000000000..e6897f831 --- /dev/null +++ b/oauth/token_auth.go @@ -0,0 +1,62 @@ +package oauth + +import ( + "time" + + "github.com/golang-jwt/jwt" + "github.com/twilio/twilio-go/client" +) + +type TokenAuth struct { + token string + tokenManager *TokenManager +} + +func NewTokenAuthInitializer(token string, tokenManager *TokenManager) *TokenAuth { + return &TokenAuth{ + token: token, + tokenManager: tokenManager, + } +} +func NewTokenAuth(grantType, clientId, clientSecret, code, audience, refreshToken, scope string) *TokenAuth { + return &TokenAuth{ + tokenManager: &TokenManager{ + GrantType: grantType, + ClientId: clientId, + ClientSecret: clientSecret, + Code: code, + Audience: audience, + RefreshToken: refreshToken, + Scope: scope, + }, + } +} + +func (t *TokenAuth) FetchToken(c client.RequestHandler) (string, error) { + if t.token != "" && !t.TokenExpired() { + return t.token, nil + } + + token, err := t.tokenManager.fetchAccessToken(c) + if err != nil { + return "", err + } + + t.token = token + return t.token, nil +} + +func (t *TokenAuth) TokenExpired() bool { + token, _, err := new(jwt.Parser).ParseUnverified(t.token, jwt.MapClaims{}) + if err != nil { + return true + } + + if claims, ok := token.Claims.(jwt.MapClaims); ok { + if exp, ok := claims["exp"].(float64); ok { + expirationTime := time.Unix(int64(exp), 0) + return time.Now().After(expirationTime) + } + } + return true +} diff --git a/oauth/token_manager.go b/oauth/token_manager.go new file mode 100644 index 000000000..fe427398b --- /dev/null +++ b/oauth/token_manager.go @@ -0,0 +1,52 @@ +package oauth + +import ( + "fmt" + + "github.com/twilio/twilio-go/client" + preview_iam "github.com/twilio/twilio-go/rest/preview_iam/v1" +) + +type TokenManager struct { + GrantType string + ClientId string + ClientSecret string + Code string + Audience string + RefreshToken string + Scope string +} + +func NewTokenManager(grantType, clientId, clientSecret, code, audience, refreshToken, scope string) *TokenManager { + return &TokenManager{ + GrantType: grantType, + ClientId: clientId, + ClientSecret: clientSecret, + Code: code, + Audience: audience, + RefreshToken: refreshToken, + Scope: scope, + } +} + +func (tm *TokenManager) fetchAccessToken(c client.RequestHandler) (string, error) { + params := &preview_iam.CreateTokenParams{} + params.SetGrantType(tm.GrantType). + SetClientId(tm.ClientId). + SetClientSecret(tm.ClientSecret). + SetCode(tm.Code). + SetAudience(tm.Audience). + SetRefreshToken(tm.RefreshToken). + SetScope(tm.Scope) + + token, err := preview_iam.NewApiService(&c).CreateToken(params) + if err != nil { + return "", err + } + + if token.AccessToken == nil { + return "", fmt.Errorf("access token is nil") + } + + return *token.AccessToken, nil +} diff --git a/rest/preview_iam/v1/README.md b/rest/preview_iam/v1/README.md new file mode 100644 index 000000000..8a6d29c9b --- /dev/null +++ b/rest/preview_iam/v1/README.md @@ -0,0 +1,94 @@ +# Go API client for openapi + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project from the OpenAPI specs located at [twilio/twilio-oai](https://github.com/twilio/twilio-oai/tree/main/spec). By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: 1.0.0 +- Build package: com.twilio.oai.TwilioGoGenerator +For more information, please visit [https://support.twilio.com](https://support.twilio.com) + +## Installation + +Install the following dependencies: + +```shell +go get github.com/stretchr/testify/assert +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```golang +import "./openapi" +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://preview-iam.twilio.com* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*AuthorizeApi* | [**FetchAuthorize**](docs/AuthorizeApi.md#fetchauthorize) | **Get** /v1/authorize | Retrieves authorize uri +*TokenApi* | [**CreateToken**](docs/TokenApi.md#createtoken) | **Post** /v1/token | Issues a new Access token (optionally identity_token & refresh_token) in exchange of Oauth grant + + +## Documentation For Models + + - [ScimError](docs/ScimError.md) + - [ScimUser](docs/ScimUser.md) + - [PublicApiCreateRoleAssignmentRequest](docs/PublicApiCreateRoleAssignmentRequest.md) + - [ScimMeta](docs/ScimMeta.md) + - [ScimName](docs/ScimName.md) + - [PublicApiRoleAssignmentResponse](docs/PublicApiRoleAssignmentResponse.md) + - [ScimResourceTypes](docs/ScimResourceTypes.md) + - [OauthV1Authorize](docs/OauthV1Authorize.md) + - [PublicApiCreateAccountResponse](docs/PublicApiCreateAccountResponse.md) + - [OauthV1Token](docs/OauthV1Token.md) + - [PublicApiCreateAccountRequest](docs/PublicApiCreateAccountRequest.md) + - [TwilioServiceErrorResponse](docs/TwilioServiceErrorResponse.md) + - [PublicApiAccountResponsePage](docs/PublicApiAccountResponsePage.md) + - [ScimPatchRequest](docs/ScimPatchRequest.md) + - [PublicApiCreateRoleAssignmentResponsePage](docs/PublicApiCreateRoleAssignmentResponsePage.md) + - [ScimUserPage](docs/ScimUserPage.md) + - [JsonPatch](docs/JsonPatch.md) + - [ScimEmailAddress](docs/ScimEmailAddress.md) + - [PublicApiAccountResponsePageMeta](docs/PublicApiAccountResponsePageMeta.md) + - [PublicApiAccountResponse](docs/PublicApiAccountResponse.md) + - [ScimPatchOperation](docs/ScimPatchOperation.md) + - [ScimResourceTypesResources](docs/ScimResourceTypesResources.md) + + +## Documentation For Authorization + + + +## oAuth2ClientCredentials + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: N/A + +Example + +```golang +auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```golang +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + diff --git a/rest/preview_iam/v1/api_service.go b/rest/preview_iam/v1/api_service.go new file mode 100644 index 000000000..831da5d4c --- /dev/null +++ b/rest/preview_iam/v1/api_service.go @@ -0,0 +1,35 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +import ( + twilio "github.com/twilio/twilio-go/client" +) + +type ApiService struct { + baseURL string + requestHandler *twilio.RequestHandler +} + +func NewApiService(requestHandler *twilio.RequestHandler) *ApiService { + return &ApiService{ + requestHandler: requestHandler, + baseURL: "https://preview-iam.twilio.com", + } +} + +func NewApiServiceWithClient(client twilio.BaseClient) *ApiService { + return NewApiService(twilio.NewRequestHandler(client)) +} diff --git a/rest/preview_iam/v1/authorize.go b/rest/preview_iam/v1/authorize.go new file mode 100644 index 000000000..bddba9103 --- /dev/null +++ b/rest/preview_iam/v1/authorize.go @@ -0,0 +1,94 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * 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 'FetchAuthorize' +type FetchAuthorizeParams struct { + // Response Type + ResponseType *string `json:"response_type,omitempty"` + // The Client Identifier + ClientId *string `json:"client_id,omitempty"` + // The url to which response will be redirected to + RedirectUri *string `json:"redirect_uri,omitempty"` + // The scope of the access request + Scope *string `json:"scope,omitempty"` + // An opaque value which can be used to maintain state between the request and callback + State *string `json:"state,omitempty"` +} + +func (params *FetchAuthorizeParams) SetResponseType(ResponseType string) *FetchAuthorizeParams { + params.ResponseType = &ResponseType + return params +} +func (params *FetchAuthorizeParams) SetClientId(ClientId string) *FetchAuthorizeParams { + params.ClientId = &ClientId + return params +} +func (params *FetchAuthorizeParams) SetRedirectUri(RedirectUri string) *FetchAuthorizeParams { + params.RedirectUri = &RedirectUri + return params +} +func (params *FetchAuthorizeParams) SetScope(Scope string) *FetchAuthorizeParams { + params.Scope = &Scope + return params +} +func (params *FetchAuthorizeParams) SetState(State string) *FetchAuthorizeParams { + params.State = &State + return params +} + +func (c *ApiService) FetchAuthorize(params *FetchAuthorizeParams) (*OauthV1Authorize, error) { + path := "/v1/authorize" + + data := url.Values{} + headers := map[string]interface{}{ + "Content-Type": "application/x-www-form-urlencoded", + } + + if params != nil && params.ResponseType != nil { + data.Set("response_type", *params.ResponseType) + } + if params != nil && params.ClientId != nil { + data.Set("client_id", *params.ClientId) + } + if params != nil && params.RedirectUri != nil { + data.Set("redirect_uri", *params.RedirectUri) + } + if params != nil && params.Scope != nil { + data.Set("scope", *params.Scope) + } + if params != nil && params.State != nil { + data.Set("state", *params.State) + } + + resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + ps := &OauthV1Authorize{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + + return ps, err +} diff --git a/rest/preview_iam/v1/docs/JsonPatch.md b/rest/preview_iam/v1/docs/JsonPatch.md new file mode 100644 index 000000000..9a1f76bcc --- /dev/null +++ b/rest/preview_iam/v1/docs/JsonPatch.md @@ -0,0 +1,13 @@ +# JsonPatch + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Op** | **string** | |[optional] +**Path** | **string** | |[optional] +**Value** | **string** | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/OauthV1Authorize.md b/rest/preview_iam/v1/docs/OauthV1Authorize.md new file mode 100644 index 000000000..e5ee8244f --- /dev/null +++ b/rest/preview_iam/v1/docs/OauthV1Authorize.md @@ -0,0 +1,11 @@ +# OauthV1Authorize + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**RedirectTo** | Pointer to **string** | The callback URL | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/OauthV1Token.md b/rest/preview_iam/v1/docs/OauthV1Token.md new file mode 100644 index 000000000..dd8662283 --- /dev/null +++ b/rest/preview_iam/v1/docs/OauthV1Token.md @@ -0,0 +1,15 @@ +# OauthV1Token + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AccessToken** | Pointer to **string** | Token which carries the necessary information to access a Twilio resource directly. | +**RefreshToken** | Pointer to **string** | Token which carries the information necessary to get a new access token. | +**IdToken** | Pointer to **string** | Token which carries the information necessary of user profile. | +**TokenType** | Pointer to **string** | Token type | +**ExpiresIn** | Pointer to **int64** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiAccountResponse.md b/rest/preview_iam/v1/docs/PublicApiAccountResponse.md new file mode 100644 index 000000000..6a0a29400 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiAccountResponse.md @@ -0,0 +1,15 @@ +# PublicApiAccountResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AccountSid** | **string** | Twilio account sid |[optional] +**FriendlyName** | **string** | Account friendly name |[optional] +**Status** | **string** | Account status |[optional] +**OwnerSid** | **string** | Twilio account sid |[optional] +**DateCreated** | [**time.Time**](time.Time.md) | The date and time when the account was created in the system |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiAccountResponsePage.md b/rest/preview_iam/v1/docs/PublicApiAccountResponsePage.md new file mode 100644 index 000000000..2eda035bb --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiAccountResponsePage.md @@ -0,0 +1,12 @@ +# PublicApiAccountResponsePage + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Content** | [**[]PublicApiAccountResponse**](PublicApiAccountResponse.md) | Page content |[optional] +**Meta** | [**PublicApiAccountResponsePageMeta**](PublicApiAccountResponsePageMeta.md) | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiAccountResponsePageMeta.md b/rest/preview_iam/v1/docs/PublicApiAccountResponsePageMeta.md new file mode 100644 index 000000000..aec29b650 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiAccountResponsePageMeta.md @@ -0,0 +1,17 @@ +# PublicApiAccountResponsePageMeta + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**FirstPageUrl** | **string** | |[optional] +**Key** | **string** | |[optional] +**NextPageUrl** | Pointer to **string** | | +**Page** | **int** | |[optional] +**PageSize** | **int** | |[optional] +**PreviousPageUrl** | Pointer to **string** | | +**Url** | **string** | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiCreateAccountRequest.md b/rest/preview_iam/v1/docs/PublicApiCreateAccountRequest.md new file mode 100644 index 000000000..5b2706eb6 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiCreateAccountRequest.md @@ -0,0 +1,12 @@ +# PublicApiCreateAccountRequest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**FriendlyName** | **string** | Account friendly name | +**OwnerSid** | **string** | Optional owner sid. If not provided, the owner will be the organization owner. |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiCreateAccountResponse.md b/rest/preview_iam/v1/docs/PublicApiCreateAccountResponse.md new file mode 100644 index 000000000..067c5c77b --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiCreateAccountResponse.md @@ -0,0 +1,11 @@ +# PublicApiCreateAccountResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AccountSid** | **string** | Twilio account sid for the new account, creation is asynchronous owner. |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentRequest.md b/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentRequest.md new file mode 100644 index 000000000..925f6d498 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentRequest.md @@ -0,0 +1,13 @@ +# PublicApiCreateRoleAssignmentRequest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**RoleSid** | **string** | Twilio Role Sid representing assigned role | +**Scope** | **string** | Twilio Sid representing scope of this assignment | +**Identity** | **string** | Twilio Sid representing identity of this assignment | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentResponsePage.md b/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentResponsePage.md new file mode 100644 index 000000000..839c156e8 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiCreateRoleAssignmentResponsePage.md @@ -0,0 +1,12 @@ +# PublicApiCreateRoleAssignmentResponsePage + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Content** | [**[]PublicApiRoleAssignmentResponse**](PublicApiRoleAssignmentResponse.md) | Page content |[optional] +**Meta** | [**PublicApiAccountResponsePageMeta**](PublicApiAccountResponsePageMeta.md) | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/PublicApiRoleAssignmentResponse.md b/rest/preview_iam/v1/docs/PublicApiRoleAssignmentResponse.md new file mode 100644 index 000000000..7abcf0900 --- /dev/null +++ b/rest/preview_iam/v1/docs/PublicApiRoleAssignmentResponse.md @@ -0,0 +1,14 @@ +# PublicApiRoleAssignmentResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Sid** | **string** | Twilio Role Assignment Sid representing this role assignment |[optional] +**RoleSid** | **string** | Twilio Role Sid representing assigned role |[optional] +**Scope** | **string** | Twilio Sid representing identity of this assignment |[optional] +**Identity** | **string** | Twilio Sid representing scope of this assignment |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimEmailAddress.md b/rest/preview_iam/v1/docs/ScimEmailAddress.md new file mode 100644 index 000000000..929e55abd --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimEmailAddress.md @@ -0,0 +1,13 @@ +# ScimEmailAddress + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Primary** | **bool** | Indicates if this email address is the primary one |[optional] +**Value** | **string** | The actual email address value |[optional] +**Type** | **string** | The type of email address (e.g., work, home, etc.) |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimError.md b/rest/preview_iam/v1/docs/ScimError.md new file mode 100644 index 000000000..bb8af8bd2 --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimError.md @@ -0,0 +1,16 @@ +# ScimError + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Schemas** | **[]string** | Schema URIs that define the contents of the error structure |[optional] +**Detail** | **string** | A human-readable description of the error |[optional] +**ScimType** | **string** | A scimType error code as defined in RFC7644 |[optional] +**Status** | **string** | Http status code |[optional] +**Code** | **int** | Twilio-specific error code |[optional] +**MoreInfo** | **string** | Link to Error Code References |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimMeta.md b/rest/preview_iam/v1/docs/ScimMeta.md new file mode 100644 index 000000000..311528b86 --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimMeta.md @@ -0,0 +1,14 @@ +# ScimMeta + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**ResourceType** | **string** | Indicates the type of the resource |[optional] +**Created** | [**time.Time**](time.Time.md) | The date and time when the resource was created in the system |[optional] +**LastModified** | [**time.Time**](time.Time.md) | The date and time when the resource was last modified |[optional] +**Version** | **string** | A version identifier for the resource. This can be used to manage resource versioning and concurrency control. |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimName.md b/rest/preview_iam/v1/docs/ScimName.md new file mode 100644 index 000000000..a43d1050b --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimName.md @@ -0,0 +1,12 @@ +# ScimName + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**GivenName** | **string** | The user's first or given name |[optional] +**FamilyName** | **string** | The user's last or family name |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimPatchOperation.md b/rest/preview_iam/v1/docs/ScimPatchOperation.md new file mode 100644 index 000000000..eeb63be40 --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimPatchOperation.md @@ -0,0 +1,13 @@ +# ScimPatchOperation + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Op** | **string** | The operation to perform |[optional] +**Path** | **string** | |[optional] +**Value** | **map[string]interface{}** | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimPatchRequest.md b/rest/preview_iam/v1/docs/ScimPatchRequest.md new file mode 100644 index 000000000..3055df4ff --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimPatchRequest.md @@ -0,0 +1,12 @@ +# ScimPatchRequest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Schemas** | **[]string** | |[optional] +**Operations** | [**[]ScimPatchOperation**](ScimPatchOperation.md) | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimResourceTypes.md b/rest/preview_iam/v1/docs/ScimResourceTypes.md new file mode 100644 index 000000000..1da1d220c --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimResourceTypes.md @@ -0,0 +1,11 @@ +# ScimResourceTypes + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Resources** | [**[]ScimResourceTypesResources**](ScimResourceTypesResources.md) | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimResourceTypesResources.md b/rest/preview_iam/v1/docs/ScimResourceTypesResources.md new file mode 100644 index 000000000..d0557e5b4 --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimResourceTypesResources.md @@ -0,0 +1,14 @@ +# ScimResourceTypesResources + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | **string** | Name of the resource type |[optional] +**Description** | **string** | Description of the resource type |[optional] +**Endpoint** | **string** | HTTP-addressable endpoint relative to the Base URL of the service provider |[optional] +**Schema** | **string** | Primary/base schema URI |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimUser.md b/rest/preview_iam/v1/docs/ScimUser.md new file mode 100644 index 000000000..2e95fe65f --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimUser.md @@ -0,0 +1,21 @@ +# ScimUser + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Id** | **string** | Unique Twilio user sid |[optional] +**ExternalId** | **string** | External unique resource id defined by provisioning client |[optional] +**UserName** | **string** | Unique username, MUST be same as primary email address | +**DisplayName** | **string** | User friendly display name |[optional] +**Name** | [**ScimName**](ScimName.md) | |[optional] +**Emails** | [**[]ScimEmailAddress**](ScimEmailAddress.md) | Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. |[optional] +**Active** | **bool** | Indicates whether the user is active |[optional] +**Locale** | **string** | User's locale |[optional] +**Timezone** | **string** | User's time zone |[optional] +**Schemas** | **[]string** | An array of URIs that indicate the schemas supported for this user resource |[optional] +**Meta** | [**ScimMeta**](ScimMeta.md) | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/ScimUserPage.md b/rest/preview_iam/v1/docs/ScimUserPage.md new file mode 100644 index 000000000..ecbc4cfb4 --- /dev/null +++ b/rest/preview_iam/v1/docs/ScimUserPage.md @@ -0,0 +1,13 @@ +# ScimUserPage + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Resources** | [**[]ScimUser**](ScimUser.md) | |[optional] +**TotalResults** | **int** | |[optional] +**Schemas** | **[]string** | |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/docs/TwilioServiceErrorResponse.md b/rest/preview_iam/v1/docs/TwilioServiceErrorResponse.md new file mode 100644 index 000000000..900ec5169 --- /dev/null +++ b/rest/preview_iam/v1/docs/TwilioServiceErrorResponse.md @@ -0,0 +1,14 @@ +# TwilioServiceErrorResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Code** | **int** | Twilio-specific error code |[optional] +**Message** | **string** | Error message |[optional] +**MoreInfo** | **string** | Link to Error Code References |[optional] +**Status** | **int** | HTTP response status code |[optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/rest/preview_iam/v1/model_json_patch.go b/rest/preview_iam/v1/model_json_patch.go new file mode 100644 index 000000000..b251132ff --- /dev/null +++ b/rest/preview_iam/v1/model_json_patch.go @@ -0,0 +1,22 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// JsonPatch struct for JsonPatch +type JsonPatch struct { + Op string `json:"op,omitempty"` + Path string `json:"path,omitempty"` + Value string `json:"value,omitempty"` +} diff --git a/rest/preview_iam/v1/model_oauth_v1_authorize.go b/rest/preview_iam/v1/model_oauth_v1_authorize.go new file mode 100644 index 000000000..3b0cc5266 --- /dev/null +++ b/rest/preview_iam/v1/model_oauth_v1_authorize.go @@ -0,0 +1,21 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// OauthV1Authorize struct for OauthV1Authorize +type OauthV1Authorize struct { + // The callback URL + RedirectTo *string `json:"redirect_to,omitempty"` +} diff --git a/rest/preview_iam/v1/model_oauth_v1_token.go b/rest/preview_iam/v1/model_oauth_v1_token.go new file mode 100644 index 000000000..20d88b389 --- /dev/null +++ b/rest/preview_iam/v1/model_oauth_v1_token.go @@ -0,0 +1,28 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// OauthV1Token struct for OauthV1Token +type OauthV1Token struct { + // Token which carries the necessary information to access a Twilio resource directly. + AccessToken *string `json:"access_token,omitempty"` + // Token which carries the information necessary to get a new access token. + RefreshToken *string `json:"refresh_token,omitempty"` + // Token which carries the information necessary of user profile. + IdToken *string `json:"id_token,omitempty"` + // Token type + TokenType *string `json:"token_type,omitempty"` + ExpiresIn *int64 `json:"expires_in,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_account_response.go b/rest/preview_iam/v1/model_public_api_account_response.go new file mode 100644 index 000000000..08cc29a0d --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_account_response.go @@ -0,0 +1,33 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +import ( + "time" +) + +// PublicApiAccountResponse Page content +type PublicApiAccountResponse struct { + // Twilio account sid + AccountSid string `json:"account_sid,omitempty"` + // Account friendly name + FriendlyName string `json:"friendly_name,omitempty"` + // Account status + Status string `json:"status,omitempty"` + // Twilio account sid + OwnerSid string `json:"owner_sid,omitempty"` + // The date and time when the account was created in the system + DateCreated time.Time `json:"date_created,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_account_response_page.go b/rest/preview_iam/v1/model_public_api_account_response_page.go new file mode 100644 index 000000000..9d619a14f --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_account_response_page.go @@ -0,0 +1,22 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiAccountResponsePage struct for PublicApiAccountResponsePage +type PublicApiAccountResponsePage struct { + // Page content + Content []PublicApiAccountResponse `json:"content,omitempty"` + Meta PublicApiAccountResponsePageMeta `json:"meta,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_account_response_page_meta.go b/rest/preview_iam/v1/model_public_api_account_response_page_meta.go new file mode 100644 index 000000000..a02d1ec80 --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_account_response_page_meta.go @@ -0,0 +1,26 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiAccountResponsePageMeta struct for PublicApiAccountResponsePageMeta +type PublicApiAccountResponsePageMeta struct { + FirstPageUrl string `json:"first_page_url,omitempty"` + Key string `json:"key,omitempty"` + NextPageUrl *string `json:"next_page_url,omitempty"` + Page int `json:"page,omitempty"` + PageSize int `json:"page_size,omitempty"` + PreviousPageUrl *string `json:"previous_page_url,omitempty"` + Url string `json:"url,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_create_account_request.go b/rest/preview_iam/v1/model_public_api_create_account_request.go new file mode 100644 index 000000000..b3175aba2 --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_create_account_request.go @@ -0,0 +1,23 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiCreateAccountRequest struct for PublicApiCreateAccountRequest +type PublicApiCreateAccountRequest struct { + // Account friendly name + FriendlyName string `json:"friendlyName"` + // Optional owner sid. If not provided, the owner will be the organization owner. + OwnerSid string `json:"ownerSid,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_create_account_response.go b/rest/preview_iam/v1/model_public_api_create_account_response.go new file mode 100644 index 000000000..eee0f698b --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_create_account_response.go @@ -0,0 +1,21 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiCreateAccountResponse struct for PublicApiCreateAccountResponse +type PublicApiCreateAccountResponse struct { + // Twilio account sid for the new account, creation is asynchronous owner. + AccountSid string `json:"accountSid,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_create_role_assignment_request.go b/rest/preview_iam/v1/model_public_api_create_role_assignment_request.go new file mode 100644 index 000000000..3e9167abb --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_create_role_assignment_request.go @@ -0,0 +1,25 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiCreateRoleAssignmentRequest struct for PublicApiCreateRoleAssignmentRequest +type PublicApiCreateRoleAssignmentRequest struct { + // Twilio Role Sid representing assigned role + RoleSid string `json:"role_sid"` + // Twilio Sid representing scope of this assignment + Scope string `json:"scope"` + // Twilio Sid representing identity of this assignment + Identity string `json:"identity"` +} diff --git a/rest/preview_iam/v1/model_public_api_create_role_assignment_response_page.go b/rest/preview_iam/v1/model_public_api_create_role_assignment_response_page.go new file mode 100644 index 000000000..dcde84690 --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_create_role_assignment_response_page.go @@ -0,0 +1,22 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiCreateRoleAssignmentResponsePage struct for PublicApiCreateRoleAssignmentResponsePage +type PublicApiCreateRoleAssignmentResponsePage struct { + // Page content + Content []PublicApiRoleAssignmentResponse `json:"content,omitempty"` + Meta PublicApiAccountResponsePageMeta `json:"meta,omitempty"` +} diff --git a/rest/preview_iam/v1/model_public_api_role_assignment_response.go b/rest/preview_iam/v1/model_public_api_role_assignment_response.go new file mode 100644 index 000000000..cca45315c --- /dev/null +++ b/rest/preview_iam/v1/model_public_api_role_assignment_response.go @@ -0,0 +1,27 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// PublicApiRoleAssignmentResponse struct for PublicApiRoleAssignmentResponse +type PublicApiRoleAssignmentResponse struct { + // Twilio Role Assignment Sid representing this role assignment + Sid string `json:"sid,omitempty"` + // Twilio Role Sid representing assigned role + RoleSid string `json:"role_sid,omitempty"` + // Twilio Sid representing identity of this assignment + Scope string `json:"scope,omitempty"` + // Twilio Sid representing scope of this assignment + Identity string `json:"identity,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_email_address.go b/rest/preview_iam/v1/model_scim_email_address.go new file mode 100644 index 000000000..4d7c3ae43 --- /dev/null +++ b/rest/preview_iam/v1/model_scim_email_address.go @@ -0,0 +1,25 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimEmailAddress Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. +type ScimEmailAddress struct { + // Indicates if this email address is the primary one + Primary bool `json:"primary,omitempty"` + // The actual email address value + Value string `json:"value,omitempty"` + // The type of email address (e.g., work, home, etc.) + Type string `json:"type,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_error.go b/rest/preview_iam/v1/model_scim_error.go new file mode 100644 index 000000000..f7597c31f --- /dev/null +++ b/rest/preview_iam/v1/model_scim_error.go @@ -0,0 +1,31 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimError struct for ScimError +type ScimError struct { + // Schema URIs that define the contents of the error structure + Schemas []string `json:"schemas,omitempty"` + // A human-readable description of the error + Detail string `json:"detail,omitempty"` + // A scimType error code as defined in RFC7644 + ScimType string `json:"scimType,omitempty"` + // Http status code + Status string `json:"status,omitempty"` + // Twilio-specific error code + Code int `json:"code,omitempty"` + // Link to Error Code References + MoreInfo string `json:"moreInfo,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_meta.go b/rest/preview_iam/v1/model_scim_meta.go new file mode 100644 index 000000000..9f0808075 --- /dev/null +++ b/rest/preview_iam/v1/model_scim_meta.go @@ -0,0 +1,31 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +import ( + "time" +) + +// ScimMeta Meta +type ScimMeta struct { + // Indicates the type of the resource + ResourceType string `json:"resourceType,omitempty"` + // The date and time when the resource was created in the system + Created time.Time `json:"created,omitempty"` + // The date and time when the resource was last modified + LastModified time.Time `json:"lastModified,omitempty"` + // A version identifier for the resource. This can be used to manage resource versioning and concurrency control. + Version string `json:"version,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_name.go b/rest/preview_iam/v1/model_scim_name.go new file mode 100644 index 000000000..a2cdbbbe9 --- /dev/null +++ b/rest/preview_iam/v1/model_scim_name.go @@ -0,0 +1,23 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimName User's name +type ScimName struct { + // The user's first or given name + GivenName string `json:"givenName,omitempty"` + // The user's last or family name + FamilyName string `json:"familyName,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_patch_operation.go b/rest/preview_iam/v1/model_scim_patch_operation.go new file mode 100644 index 000000000..ad3ca523b --- /dev/null +++ b/rest/preview_iam/v1/model_scim_patch_operation.go @@ -0,0 +1,23 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimPatchOperation struct for ScimPatchOperation +type ScimPatchOperation struct { + // The operation to perform + Op string `json:"op,omitempty"` + Path string `json:"path,omitempty"` + Value map[string]interface{} `json:"value,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_patch_request.go b/rest/preview_iam/v1/model_scim_patch_request.go new file mode 100644 index 000000000..eb9f3d09d --- /dev/null +++ b/rest/preview_iam/v1/model_scim_patch_request.go @@ -0,0 +1,21 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimPatchRequest struct for ScimPatchRequest +type ScimPatchRequest struct { + Schemas []string `json:"schemas,omitempty"` + Operations []ScimPatchOperation `json:"Operations,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_resource_types.go b/rest/preview_iam/v1/model_scim_resource_types.go new file mode 100644 index 000000000..5b0ac6c50 --- /dev/null +++ b/rest/preview_iam/v1/model_scim_resource_types.go @@ -0,0 +1,20 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimResourceTypes struct for ScimResourceTypes +type ScimResourceTypes struct { + Resources []ScimResourceTypesResources `json:"Resources,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_resource_types_resources.go b/rest/preview_iam/v1/model_scim_resource_types_resources.go new file mode 100644 index 000000000..0409454f0 --- /dev/null +++ b/rest/preview_iam/v1/model_scim_resource_types_resources.go @@ -0,0 +1,27 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimResourceTypesResources struct for ScimResourceTypesResources +type ScimResourceTypesResources struct { + // Name of the resource type + Name string `json:"name,omitempty"` + // Description of the resource type + Description string `json:"description,omitempty"` + // HTTP-addressable endpoint relative to the Base URL of the service provider + Endpoint string `json:"endpoint,omitempty"` + // Primary/base schema URI + Schema string `json:"schema,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_user.go b/rest/preview_iam/v1/model_scim_user.go new file mode 100644 index 000000000..a64b5bc9d --- /dev/null +++ b/rest/preview_iam/v1/model_scim_user.go @@ -0,0 +1,39 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimUser struct for ScimUser +type ScimUser struct { + // Unique Twilio user sid + Id string `json:"id,omitempty"` + // External unique resource id defined by provisioning client + ExternalId string `json:"externalId,omitempty"` + // Unique username, MUST be same as primary email address + UserName string `json:"userName"` + // User friendly display name + DisplayName string `json:"displayName,omitempty"` + Name ScimName `json:"name,omitempty"` + // Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. + Emails []ScimEmailAddress `json:"emails,omitempty"` + // Indicates whether the user is active + Active bool `json:"active,omitempty"` + // User's locale + Locale string `json:"locale,omitempty"` + // User's time zone + Timezone string `json:"timezone,omitempty"` + // An array of URIs that indicate the schemas supported for this user resource + Schemas []string `json:"schemas,omitempty"` + Meta ScimMeta `json:"meta,omitempty"` +} diff --git a/rest/preview_iam/v1/model_scim_user_page.go b/rest/preview_iam/v1/model_scim_user_page.go new file mode 100644 index 000000000..b5a99179f --- /dev/null +++ b/rest/preview_iam/v1/model_scim_user_page.go @@ -0,0 +1,22 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// ScimUserPage struct for ScimUserPage +type ScimUserPage struct { + Resources []ScimUser `json:"Resources,omitempty"` + TotalResults int `json:"totalResults,omitempty"` + Schemas []string `json:"schemas,omitempty"` +} diff --git a/rest/preview_iam/v1/model_twilio_service_error_response.go b/rest/preview_iam/v1/model_twilio_service_error_response.go new file mode 100644 index 000000000..77d19d014 --- /dev/null +++ b/rest/preview_iam/v1/model_twilio_service_error_response.go @@ -0,0 +1,27 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package openapi + +// TwilioServiceErrorResponse struct for TwilioServiceErrorResponse +type TwilioServiceErrorResponse struct { + // Twilio-specific error code + Code int `json:"code,omitempty"` + // Error message + Message string `json:"message,omitempty"` + // Link to Error Code References + MoreInfo string `json:"moreInfo,omitempty"` + // HTTP response status code + Status int `json:"status,omitempty"` +} diff --git a/rest/preview_iam/v1/token.go b/rest/preview_iam/v1/token.go new file mode 100644 index 000000000..22d93f839 --- /dev/null +++ b/rest/preview_iam/v1/token.go @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * 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:"grant_type,omitempty"` + // A 34 character string that uniquely identifies this OAuth App. + ClientId *string `json:"client_id,omitempty"` + // The credential for confidential OAuth App. + ClientSecret *string `json:"client_secret,omitempty"` + // JWT token related to the authorization code grant type. + Code *string `json:"code,omitempty"` + // The redirect uri + RedirectUri *string `json:"redirect_uri,omitempty"` + // The targeted audience uri + Audience *string `json:"audience,omitempty"` + // JWT token related to refresh access token. + RefreshToken *string `json:"refresh_token,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 +} + +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("grant_type", *params.GrantType) + } + if params != nil && params.ClientId != nil { + data.Set("client_id", *params.ClientId) + } + if params != nil && params.ClientSecret != nil { + data.Set("client_secret", *params.ClientSecret) + } + if params != nil && params.Code != nil { + data.Set("code", *params.Code) + } + if params != nil && params.RedirectUri != nil { + data.Set("redirect_uri", *params.RedirectUri) + } + if params != nil && params.Audience != nil { + data.Set("audience", *params.Audience) + } + if params != nil && params.RefreshToken != nil { + data.Set("refresh_token", *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 +} diff --git a/test.go b/test.go new file mode 100644 index 000000000..bdef3d757 --- /dev/null +++ b/test.go @@ -0,0 +1 @@ +package twilio diff --git a/twilio.go b/twilio.go index 86313e9ca..5a2a2fd8d 100644 --- a/twilio.go +++ b/twilio.go @@ -125,18 +125,25 @@ type Meta struct { URL *string `json:"url"` } +type ClientCredentialProvider struct { + GrantType string + ClientId string + ClientSecret string +} + type ClientParams struct { - Username string - Password string - AccountSid string - Client client.BaseClient + Username string + Password string + AccountSid string + Client client.BaseClient + ClientCredentialProvider *ClientCredentialProvider } // NewRestClientWithParams provides an initialized Twilio RestClient with params. func NewRestClientWithParams(params ClientParams) *RestClient { requestHandler := client.NewRequestHandler(params.Client) - if params.Client == nil { + if params.Client == nil && params.ClientCredentialProvider == nil { username := params.Username if username == "" { username = os.Getenv("TWILIO_ACCOUNT_SID") @@ -157,6 +164,17 @@ func NewRestClientWithParams(params ClientParams) *RestClient { defaultClient.SetAccountSid(username) } requestHandler = client.NewRequestHandler(defaultClient) + } else if params.ClientCredentialProvider != nil { + defaultClient := &client.Client{ + Credentials: client.NewCredentials("", ""), + } + handler := client.NewRequestHandler(defaultClient) + clientCredentials := client.NewClientCredentials(params.ClientCredentialProvider.GrantType, params.ClientCredentialProvider.ClientId, params.ClientCredentialProvider.ClientSecret, *handler) + defaultClient.SetClientCredentials(clientCredentials) + if params.AccountSid != "" { + defaultClient.SetAccountSid(params.AccountSid) + } + requestHandler = client.NewRequestHandler(defaultClient) } c := &RestClient{ From ff129f94060ee786645f3e640bbbf64e2ff0e4bc Mon Sep 17 00:00:00 2001 From: manisha1997 Date: Thu, 20 Mar 2025 19:36:48 +0530 Subject: [PATCH 2/2] feat: auth feature --- client/client.go | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/client/client.go b/client/client.go index a058f65e2..2b5a6c5bc 100644 --- a/client/client.go +++ b/client/client.go @@ -13,12 +13,10 @@ import ( "strings" "time" - "github.com/golang-jwt/jwt" "github.com/twilio/twilio-go/oauth" "github.com/pkg/errors" "github.com/twilio/twilio-go/client/form" - preview_iam "github.com/twilio/twilio-go/rest/preview_iam/v1" ) var alphanumericRegex *regexp.Regexp @@ -247,45 +245,3 @@ func (c *Client) SetAccountSid(sid string) { func (c *Client) AccountSid() string { return c.accountSid } - -func GetAccessToken(grantType, clientId, clientSecret, code, redirectUri, audience, refreshToken, scope string, c RequestHandler) (string, error) { - params := &preview_iam.CreateTokenParams{} - params.SetGrantType(grantType). - SetClientId(clientId). - SetClientSecret(clientSecret). - SetCode(code). - SetRedirectUri(redirectUri). - SetAudience(audience). - SetRefreshToken(refreshToken). - SetScope(scope) - - token, err := preview_iam.NewApiService(&c).CreateToken(params) - if err != nil { - return "", err - } - - if token.AccessToken == nil { - return "", fmt.Errorf("access token is nil") - } - - return *token.AccessToken, nil -} - -func TokenExpired(tokenString string) bool { - // Parse the token without validating the signature - token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{}) - if err != nil { - return true // Consider token expired if there's an error parsing it - } - - // Extract the claims - if claims, ok := token.Claims.(jwt.MapClaims); ok { - // Get the expiration time - if exp, ok := claims["exp"].(float64); ok { - // Check if the token has expired - expirationTime := time.Unix(int64(exp), 0) - return time.Now().After(expirationTime) - } - } - return true // Cons -}