Skip to content

feat: support specifying client_id on oauth2 client creation#125

Closed
KT-Doan wants to merge 1 commit intomainfrom
KevinTDoan/feat/oauth2-custom-client-id
Closed

feat: support specifying client_id on oauth2 client creation#125
KT-Doan wants to merge 1 commit intomainfrom
KevinTDoan/feat/oauth2-custom-client-id

Conversation

@KT-Doan
Copy link
Copy Markdown
Collaborator

@KT-Doan KT-Doan commented Mar 17, 2026

Description

Support specifying a custom client_id when creating OAuth2 client resources, matching the Ory API's existing capability. This allows users to maintain consistent naming conventions across environments (e.g., migrating from self-hosted Hydra to Ory Network).

Related Issues

Fixes #121

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING guide
  • My code follows the existing code style
  • I have added tests that prove my fix/feature works
  • I have updated documentation as needed
  • All new and existing tests pass (make test)
  • I have run the linter (make format)

Testing

  • Unit tests
  • Acceptance tests
  • Manual testing

Changes

Schema (internal/resources/oauth2client/resource.go):

  • Changed client_id attribute from Computed to Optional+Computed
  • Added RequiresReplace() plan modifier (changing client_id forces recreation)

Create (internal/resources/oauth2client/resource.go):

  • Pass user-specified client_id to the Ory API on creation

Tests (internal/resources/oauth2client/resource_test.go):

  • Added TestAccOAuth2ClientResource_withCustomClientID covering create, import, and update with a custom client_id

Documentation:

  • Updated templates/resources/oauth2_client.md.tmpl with Custom Client ID section
  • Added example in examples/resources/ory_oauth2_client/resource.tf
  • Updated inline schema description

Acceptance Test Results

All 9 OAuth2 client acceptance tests pass:

--- PASS: TestAccOAuth2ClientResource_basic (5.45s)
--- PASS: TestAccOAuth2ClientResource_withAudience (3.14s)
--- PASS: TestAccOAuth2ClientResource_withRedirectURIs (3.28s)
--- PASS: TestAccOAuth2ClientResource_withNewFields (3.54s)
--- PASS: TestAccOAuth2ClientResource_withConsentAndSubjectType (3.63s)
--- PASS: TestAccOAuth2ClientResource_withJWKS (5.23s)
--- PASS: TestAccOAuth2ClientResource_withResourceCredentials (3.55s)
--- PASS: TestAccOAuth2ClientResource_withCustomClientID (5.52s)
--- PASS: TestAccOAuth2ClientResource_withTokenLifespans (3.53s)

Security Scans

All pass clean:

  • make sec (govulncheck, gosec, gitleaks) - 0 issues
  • make sec-trivy - 0 findings
  • make licenses - passed

🤖 Generated with Claude Code

Allow users to specify a custom `client_id` when creating an OAuth2
client resource, matching the Ory API capability. The field is
Optional+Computed with RequiresReplace, so changing it forces recreation.

Closes #121

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 17, 2026 04:59
@KT-Doan KT-Doan closed this Mar 17, 2026
@KT-Doan KT-Doan deleted the KevinTDoan/feat/oauth2-custom-client-id branch March 17, 2026 05:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for user-specified client_id when creating ory_oauth2_client resources (matching Ory API behavior), including docs and acceptance coverage.

Changes:

  • Make client_id Optional+Computed and mark changes as RequiresReplace().
  • Pass client_id through to the Ory API on create when provided.
  • Add acceptance test coverage and update docs/examples to explain custom IDs.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
templates/resources/oauth2_client.md.tmpl Documents how to set a custom client_id, including replace behavior note.
internal/resources/oauth2client/testdata/with_custom_client_id.tf.tmpl Adds acceptance test config template for creating with a custom client_id.
internal/resources/oauth2client/testdata/with_custom_client_id_updated.tf.tmpl Adds acceptance test config template for updating non-ID fields while keeping client_id stable.
internal/resources/oauth2client/resource_test.go Adds acceptance test covering create/import/update with a custom client_id.
internal/resources/oauth2client/resource.go Updates schema (Optional+Computed + RequiresReplace) and passes client_id to API on create; updates in-file HCL example.
examples/resources/ory_oauth2_client/resource.tf Adds an example resource using a custom client_id.
docs/resources/oauth2_client.md Publishes the generated docs updates reflecting the new client_id behavior and example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 159 to 167
"client_id": schema.StringAttribute{
Description: "The OAuth2 client ID.",
Description: "The OAuth2 client ID. If not specified, a random ID will be generated. Once set, changing this value forces recreation of the resource.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
stringplanmodifier.RequiresReplace(),
},
},
}

output "client_id" {
value = ory_oauth2_client.api.client_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support specifying client id as part of oauth2 client resource

2 participants