Skip to content

Commit

Permalink
Merge pull request #1648 from matthewheath/add-custom-access-token-at…
Browse files Browse the repository at this point in the history
…tributes-to-refresh-token

Add custom token attributes to Refresh Token Request
  • Loading branch information
nbulaj committed Mar 23, 2023
2 parents 313af27 + ae4670f commit f749791
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ User-visible changes worth mentioning.
## main

- [#ID] Add your PR description here.
- [#1648] Add custom token attributes to Refresh Token Request
- [#1644] Update HTTP headers.

# 5.6.5
Expand Down
10 changes: 9 additions & 1 deletion lib/doorkeeper/oauth/refresh_token_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def default_scopes
end

def create_access_token
attributes = {}
attributes = {}.merge(custom_token_attributes_with_data)

resource_owner =
if Doorkeeper.config.polymorphic_resource_owner?
Expand Down Expand Up @@ -119,6 +119,14 @@ def validate_scope
true
end
end

def custom_token_attributes_with_data
refresh_token
.attributes
.with_indifferent_access
.slice(*Doorkeeper.config.custom_access_token_attributes)
.symbolize_keys
end
end
end
end
27 changes: 27 additions & 0 deletions spec/requests/flows/refresh_token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@
end
end

context "when custom_access_token_attributes are configured" do
before do
Doorkeeper.configure do
orm DOORKEEPER_ORM
custom_access_token_attributes [:tenant_name]
end

@token = FactoryBot.create(
:access_token,
application: @client,
resource_owner_id: resource_owner.id,
resource_owner_type: resource_owner.class.name,
use_refresh_token: true,
tenant_name: "Tenant 1",
)
end

it "copies custom attributes from the previous token into the new token" do
post refresh_token_endpoint_url(
client: @client, refresh_token: @token.refresh_token,
)

new_token = Doorkeeper::AccessToken.last
expect(new_token.tenant_name).to eq("Tenant 1")
end
end

def last_token
Doorkeeper::AccessToken.last_authorized_token_for(
@client.id, resource_owner,
Expand Down

0 comments on commit f749791

Please sign in to comment.