Skip to content

Commit 05578fc

Browse files
committed
Add JKWS endpoint for GOV.UK One Login public key
Add a publicly accessible endpoint that returns a JSON Web Key Set (JWKS) to share our public key with GOV.UK One Login.
1 parent 46b8549 commit 05578fc

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class OneLoginJwksController < ApplicationController
2+
def show
3+
jwk = Rails.application.config.x.one_login.public_key_jwk
4+
render json: JWT::JWK::Set.new(jwk).export
5+
end
6+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
get "/submission" => "submission_status#status", as: :status
2020
get "/.well-known/security.txt" => redirect("https://vulnerability-reporting.service.security.gov.uk/.well-known/security.txt")
2121

22+
get "/govuk-one-login-jwks", to: "one_login_jwks#show", as: :one_login_jwks
23+
2224
form_id_constraints = { form_id: UrlPatterns::FORM_ID_REGEX }
2325
form_constraints = {
2426
**form_id_constraints,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require "rails_helper"
2+
require "base64"
3+
4+
RSpec.describe OneLoginJwksController, type: :request do
5+
describe "GET #show" do
6+
before do
7+
public_key = OpenSSL::PKey::RSA.generate(2048).public_key
8+
public_key_jwk = JWT::JWK.new(public_key, use: "sig")
9+
10+
one_login_config = ActiveSupport::OrderedOptions.new
11+
one_login_config.public_key_jwk = public_key_jwk
12+
13+
allow(Rails.application.config.x).to receive(:one_login).and_return(one_login_config)
14+
end
15+
16+
it "returns the JWKS JSON" do
17+
get one_login_jwks_path
18+
19+
expect(response).to have_http_status(:ok)
20+
expect(response.content_type).to eq("application/json; charset=utf-8")
21+
expect(response.parsed_body).to match({
22+
"keys" => [
23+
{
24+
"e" => "AQAB",
25+
"kty" => "RSA",
26+
"use" => "sig",
27+
"kid" => a_kind_of(String),
28+
"n" => a_kind_of(String),
29+
},
30+
],
31+
})
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)