Skip to content

Commit

Permalink
Expose the technical keys of group and role type in the oauth profile
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobeltrame committed Aug 25, 2021
1 parent 3d362e8 commit b9faa03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/controllers/oauth/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def public_attrs_with_roles
{
group_id: role.group_id,
group_name: role.group.name,
group_type: role.group.type,
role_name: role.class.model_name.human,
role_type: role.class.model_name,
permissions: role.class.permissions
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/oauth_applications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def format_doorkeeper_application_scopes(application)
end

def format_doorkeeper_application_scope(key)
Oauth::Application.human_scope(key) << " " << muted("(#{key})")
Oauth::Application.human_scope(key) + " " + muted("(#{key})")
end

end
11 changes: 6 additions & 5 deletions spec/requests/oauth_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@

context 'with email scope in token' do
let(:token) { Fabricate(:access_token, application: application, scopes: { scopes: 'email' }, resource_owner_id: user.id ) }

context 'with bad token signature' do
it 'fails with HTTP 401 (unauthorized)' do
get '/oauth/profile', headers: { 'Authorization': 'Bearer ' + token.token + 'X'}

expect(response).to have_http_status(:unauthorized)
end
end

context 'with wrong scope in request' do
it 'fails with HTTP 403 (forbidden)' do
get '/oauth/profile', headers: { 'Authorization': 'Bearer ' + token.token, 'X-Scope': 'name' }

expect(response).to have_http_status(:forbidden)
expect(response.content_type).to eq('application/json; charset=utf-8')
expect(response.body).to eq('{"error":"invalid scope: name"}')
Expand Down Expand Up @@ -76,7 +76,7 @@
it 'fails with 401 (unauthorized)' do
get '/oauth/profile', headers: { 'Authorization': 'Bearer ' + token.token }

expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(:unauthorized)
end
end

Expand Down Expand Up @@ -105,7 +105,8 @@

expect(response).to have_http_status(:ok)
expect(response.content_type).to eq('application/json; charset=utf-8')
expect(response.body).to include('"group_name":"Bottom One","role_name":"Member"')
expect(response.body).to include('"group_name":"Bottom One"')
expect(response.body).to include('"role_name":"Member"')
end
end
end
Expand Down

0 comments on commit b9faa03

Please sign in to comment.