Skip to content

Commit

Permalink
Merge pull request #180 from stanhu/sh-add-pkce-support
Browse files Browse the repository at this point in the history
Add PKCE support to OpenID discovery endpoint
  • Loading branch information
nbulaj authored Nov 26, 2022
2 parents e8f2d13 + ffda2dd commit a5235fd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Unreleased

- [#] Add here
- [#180] Add PKCE support to OpenID discovery endpoint

## v1.8.2 (2022-07-13)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def provider_response
exp
iat
] | openid_connect.claims.to_h.keys,

code_challenge_methods_supported: code_challenge_methods_supported(doorkeeper),
}.compact
end

Expand All @@ -81,6 +83,12 @@ def response_modes_supported(doorkeeper)
doorkeeper.authorization_response_flows.flat_map(&:response_mode_matches).uniq
end

def code_challenge_methods_supported(doorkeeper)
return unless doorkeeper.access_grant_model.pkce_supported?

%w[plain S256]
end

def webfinger_response
{
subject: params.require(:resource),
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/discovery_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
id_token_response
user_info_response
],

'code_challenge_methods_supported' => %w[
plain
S256
],
}.sort)
end

Expand Down
8 changes: 8 additions & 0 deletions spec/dummy/db/migrate/20221122044143_enable_pkce.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class EnablePkce < ActiveRecord::Migration[6.0]
def change
add_column :oauth_access_grants, :code_challenge, :string, null: true
add_column :oauth_access_grants, :code_challenge_method, :string, null: true
end
end
4 changes: 3 additions & 1 deletion spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_05_19_091115) do
ActiveRecord::Schema.define(version: 2022_11_22_044143) do

create_table "oauth_access_grants", force: :cascade do |t|
t.integer "resource_owner_id", null: false
Expand All @@ -21,6 +21,8 @@
t.datetime "created_at", null: false
t.datetime "revoked_at"
t.string "scopes"
t.string "code_challenge"
t.string "code_challenge_method"
t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
end

Expand Down
2 changes: 2 additions & 0 deletions spec/lib/oauth/authorization/code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
allow(pre_auth).to receive(:redirect_uri).and_return('redirect_uri')
allow(pre_auth).to receive(:scopes).and_return('scopes')
allow(pre_auth).to receive(:nonce).and_return('123456')
allow(pre_auth).to receive(:code_challenge).and_return('987654')
allow(pre_auth).to receive(:code_challenge_method).and_return('plain')
allow(client).to receive(:id).and_return('client_id')

allow(Doorkeeper::AccessGrant).to receive(:create!) { access_grant }
Expand Down

0 comments on commit a5235fd

Please sign in to comment.