## Create OAuth Client `client.IAM.OAuthClients.New(ctx, params) (*OAuthClientNewResponse, error)` **post** `/accounts/{account_id}/oauth_clients` Create a new OAuth client for an account. ### Parameters - `params OAuthClientNewParams` - `AccountID param.Field[string]` Path param: Account identifier tag. - `ClientName param.Field[string]` Body param: Human-readable name of the OAuth client. - `GrantTypes param.Field[[]OAuthClientNewParamsGrantType]` Body param: Array of OAuth grant types the client is allowed to use. `authorization_code` is required; `refresh_token` may be included optionally. - `const OAuthClientNewParamsGrantTypeAuthorizationCode OAuthClientNewParamsGrantType = "authorization_code"` - `const OAuthClientNewParamsGrantTypeRefreshToken OAuthClientNewParamsGrantType = "refresh_token"` - `RedirectURIs param.Field[[]string]` Body param: Array of allowed redirect URIs for the client. - `ResponseTypes param.Field[[]OAuthClientNewParamsResponseType]` Body param: Array of OAuth response types the client is allowed to use. - `const OAuthClientNewParamsResponseTypeToken OAuthClientNewParamsResponseType = "token"` - `const OAuthClientNewParamsResponseTypeIDToken OAuthClientNewParamsResponseType = "id_token"` - `const OAuthClientNewParamsResponseTypeCode OAuthClientNewParamsResponseType = "code"` - `Scopes param.Field[[]string]` Body param: Array of OAuth scopes the client is allowed to request. Colon-delimited scopes are not accepted. Dot-delimited scopes are validated against available OAuth API scopes; simple identity scopes are allowed. Protocol scopes `offline_access` and `openid` are added or removed automatically based on `grant_types` and `response_types`. - `TokenEndpointAuthMethod param.Field[OAuthClientNewParamsTokenEndpointAuthMethod]` Body param: The authentication method the client uses at the token endpoint. - `const OAuthClientNewParamsTokenEndpointAuthMethodNone OAuthClientNewParamsTokenEndpointAuthMethod = "none"` - `const OAuthClientNewParamsTokenEndpointAuthMethodClientSecretBasic OAuthClientNewParamsTokenEndpointAuthMethod = "client_secret_basic"` - `const OAuthClientNewParamsTokenEndpointAuthMethodClientSecretPost OAuthClientNewParamsTokenEndpointAuthMethod = "client_secret_post"` - `AllowedCORSOrigins param.Field[[]string]` Body param: Array of allowed CORS origins. - `ClientURI param.Field[string]` Body param: URL of the home page of the client. - `LogoURI param.Field[string]` Body param: URL of the client's logo. - `PolicyURI param.Field[string]` Body param: URL that points to a privacy policy document. - `PostLogoutRedirectURIs param.Field[[]string]` Body param: Array of allowed post-logout redirect URIs. - `TosURI param.Field[string]` Body param: URL that points to a terms of service document. ### Returns - `type OAuthClientNewResponse struct{…}` Fields shared by OAuth client responses and create/update requests. - `ClientID string` The unique identifier for an OAuth client. - `Visibility OAuthClientNewResponseVisibility` Visibility of the OAuth client. - `const OAuthClientNewResponseVisibilityPublic OAuthClientNewResponseVisibility = "public"` - `const OAuthClientNewResponseVisibilityPrivate OAuthClientNewResponseVisibility = "private"` - `AllowedCORSOrigins []string` Array of allowed CORS origins. - `ClientName string` Human-readable name of the OAuth client. - `ClientSecret string` The client secret. This is the only time the secret is returned in a response. - `ClientURI string` URL of the home page of the client. - `ClientURIVerification OAuthClientNewResponseClientURIVerification` Client URI domain control verification state. - `Status OAuthClientNewResponseClientURIVerificationStatus` Current verification status for the client URI host. - `const OAuthClientNewResponseClientURIVerificationStatusPending OAuthClientNewResponseClientURIVerificationStatus = "pending"` - `const OAuthClientNewResponseClientURIVerificationStatusInProgress OAuthClientNewResponseClientURIVerificationStatus = "in_progress"` - `const OAuthClientNewResponseClientURIVerificationStatusVerified OAuthClientNewResponseClientURIVerificationStatus = "verified"` - `const OAuthClientNewResponseClientURIVerificationStatusFailed OAuthClientNewResponseClientURIVerificationStatus = "failed"` - `Text string` Exact TXT record value that must be added to DNS to prove ownership of the client URI host. - `CreatedAt Time` Timestamp when the OAuth client was created. - `GrantTypes []OAuthClientNewResponseGrantType` Array of OAuth grant types the client is allowed to use. `authorization_code` is required; `refresh_token` may be included optionally. - `const OAuthClientNewResponseGrantTypeAuthorizationCode OAuthClientNewResponseGrantType = "authorization_code"` - `const OAuthClientNewResponseGrantTypeRefreshToken OAuthClientNewResponseGrantType = "refresh_token"` - `HasRotatedSecret bool` Indicates whether the client has a rotated secret that has not yet been deleted. - `LogoURI string` URL of the client's logo. - `PolicyURI string` URL that points to a privacy policy document. - `PostLogoutRedirectURIs []string` Array of allowed post-logout redirect URIs. - `PromotedAt Time` Timestamp when the OAuth client was promoted to public visibility. - `RedirectURIs []string` Array of allowed redirect URIs for the client. - `ResponseTypes []OAuthClientNewResponseResponseType` Array of OAuth response types the client is allowed to use. - `const OAuthClientNewResponseResponseTypeToken OAuthClientNewResponseResponseType = "token"` - `const OAuthClientNewResponseResponseTypeIDToken OAuthClientNewResponseResponseType = "id_token"` - `const OAuthClientNewResponseResponseTypeCode OAuthClientNewResponseResponseType = "code"` - `Scopes []string` Array of OAuth scopes the client is allowed to request. Colon-delimited scopes are not accepted. Dot-delimited scopes are validated against available OAuth API scopes; simple identity scopes are allowed. Protocol scopes `offline_access` and `openid` are added or removed automatically based on `grant_types` and `response_types`. - `TokenEndpointAuthMethod OAuthClientNewResponseTokenEndpointAuthMethod` The authentication method the client uses at the token endpoint. - `const OAuthClientNewResponseTokenEndpointAuthMethodNone OAuthClientNewResponseTokenEndpointAuthMethod = "none"` - `const OAuthClientNewResponseTokenEndpointAuthMethodClientSecretBasic OAuthClientNewResponseTokenEndpointAuthMethod = "client_secret_basic"` - `const OAuthClientNewResponseTokenEndpointAuthMethodClientSecretPost OAuthClientNewResponseTokenEndpointAuthMethod = "client_secret_post"` - `TosURI string` URL that points to a terms of service document. - `UpdatedAt Time` Timestamp when the OAuth client was last updated. ### Example ```go package main import ( "context" "fmt" "github.com/cloudflare/cloudflare-go" "github.com/cloudflare/cloudflare-go/iam" "github.com/cloudflare/cloudflare-go/option" ) func main() { client := cloudflare.NewClient( option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"), ) oauthClient, err := client.IAM.OAuthClients.New(context.TODO(), iam.OAuthClientNewParams{ AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), ClientName: cloudflare.F("My OAuth App"), GrantTypes: cloudflare.F([]iam.OAuthClientNewParamsGrantType{iam.OAuthClientNewParamsGrantTypeAuthorizationCode, iam.OAuthClientNewParamsGrantTypeRefreshToken}), RedirectURIs: cloudflare.F([]string{"https://example.com/callback"}), ResponseTypes: cloudflare.F([]iam.OAuthClientNewParamsResponseType{iam.OAuthClientNewParamsResponseTypeCode}), Scopes: cloudflare.F([]string{"account.read"}), TokenEndpointAuthMethod: cloudflare.F(iam.OAuthClientNewParamsTokenEndpointAuthMethodClientSecretPost), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", oauthClient.ClientID) } ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "success": true, "result": { "client_id": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4", "visibility": "private", "allowed_cors_origins": [ "https://example.com" ], "client_name": "My OAuth App", "client_secret": "cf-oauth-secret-example", "client_uri": "https://example.com", "client_uri_verification": { "status": "in_progress", "text": "cloudflare_oauth_client_publisher=example" }, "created_at": "2025-01-01T00:00:00Z", "grant_types": [ "authorization_code", "refresh_token" ], "has_rotated_secret": false, "logo_uri": "https://example.com/logo.png", "policy_uri": "https://example.com/privacy", "post_logout_redirect_uris": [ "https://example.com/logout" ], "promoted_at": "2026-05-13T12:00:00Z", "redirect_uris": [ "https://example.com/callback" ], "response_types": [ "code" ], "scopes": [ "account.read" ], "token_endpoint_auth_method": "client_secret_post", "tos_uri": "https://example.com/tos", "updated_at": "2025-01-01T00:00:00Z" } } ```