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

Add custom token attributes to Refresh Token Request #1648

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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