Skip to content

Commit

Permalink
Merge pull request #1697 from kmayer/kmayer-customzied-token-response
Browse files Browse the repository at this point in the history
Allow a TokenResponse body to be customized
  • Loading branch information
nbulaj committed Mar 13, 2024
2 parents 9a3b782 + 01343d1 commit e93f2d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ User-visible changes worth mentioning.
## main

- [#1696] Add missing `#issued_token` method to `OAuth::TokenResponse`
- [#1697] Allow a TokenResponse body to be customized.

## 5.6.9

Expand Down
2 changes: 1 addition & 1 deletion lib/doorkeeper/oauth/token_response.rb
Expand Up @@ -12,7 +12,7 @@ def initialize(token)
end

def body
{
@body ||= {
"access_token" => token.plaintext_token,
"token_type" => token.token_type,
"expires_in" => token.expires_in_seconds,
Expand Down
22 changes: 22 additions & 0 deletions spec/lib/oauth/token_response_spec.rb
Expand Up @@ -55,6 +55,28 @@
end
end

describe ".body attributes" do
subject(:token_response) { described_class.new(access_token) }

let(:access_token) do
double :access_token,
plaintext_token: "some-token",
expires_in: "3600",
expires_in_seconds: "300",
scopes_string: "two scopes",
plaintext_refresh_token: "some-refresh-token",
token_type: "Bearer",
custom_parameter: "custom_value",
created_at: 0
end

it "can be augmented" do
token_response.body["custom_parameter"] = access_token.custom_parameter

expect(token_response.body["custom_parameter"]).to eq("custom_value")
end
end

describe ".body filters out empty values" do
subject(:body) { described_class.new(access_token).body }

Expand Down

0 comments on commit e93f2d7

Please sign in to comment.