Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a TokenResponse body to be customized #1697

Merged
merged 2 commits into from Mar 13, 2024

Conversation

kmayer
Copy link
Contributor

@kmayer kmayer commented Mar 11, 2024

We have a use case where we need to include some additional information in the token response body to help the client applications with our multi-tenant setup.

Adding the memoization allows us to modify the body object during the after_successful_authorization callback:

  after_successful_authorization do |controller, context|
    case context.auth
    when Doorkeeper::OAuth::TokenResponse
      context.auth.body["tenant_id"] = context.auth.token.tenant_id
    end
  end

(Assuming that tenant_id was added to custom_access_token_attributes.)

I considered adding attributes via custom_access_token_attributes in #body directly, but that would change the existing behavior of the TokenResponse everywhere.

Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Can you please rebase? 🙏

We have a use case where we need to include some additional information
in the token response body to help the client applications with our
multi-tenant setup.

Adding the memoization allows us to modify the body object during the
after_successful_authorization callback:

```ruby
  after_successful_authorization do |controller, context|
    case context.auth
    when Doorkeeper::OAuth::TokenResponse
      context.auth.body["tenant_id"] = context.auth.token.tenant_id
    end
  end
```

(Assuming that `tenant_id` was added to `custom_access_token_attributes`.)

I considered adding attributes via `custom_access_token_attributes` in
`#body` directly, but that would change the existing behavior of the
`TokenResponse` everywhere.
@kmayer kmayer force-pushed the kmayer-customzied-token-response branch from 4688196 to 01343d1 Compare March 12, 2024 15:42
@kmayer
Copy link
Contributor Author

kmayer commented Mar 12, 2024 via email

@nbulaj nbulaj merged commit e93f2d7 into doorkeeper-gem:main Mar 13, 2024
21 of 22 checks passed
@alexookah
Copy link

@kmayer
I am also interested using this. Can you provide an example how to customize the body response?

@kmayer
Copy link
Contributor Author

kmayer commented Mar 13, 2024 via email

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.

None yet

3 participants