-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
connect login.gov oidc configuration
- Loading branch information
Showing
12 changed files
with
196 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class SessionsController < ApplicationController | ||
|
||
before_action :handle_result_error, :well_known_configuration, :decode_token, only: [:result] | ||
|
||
def new | ||
# TODO: handle redirect to login page due to inactivity | ||
end | ||
|
||
def create | ||
login_gov = LoginGov.new | ||
redirect_to(login_gov.authorization_url, allow_other_host: true) | ||
end | ||
|
||
def delete | ||
login_gov = LoginGov.new | ||
# TODO: update user session status, clear out JWT | ||
# TODO: add session duration to the security log | ||
# TODO: delete session locally and Phoenix | ||
redirect_to(login_gov.logout_url) | ||
end | ||
|
||
def result | ||
|
||
end | ||
|
||
private | ||
|
||
def handle_result_error | ||
if params[:error] | ||
Rails.logger.error("Login.gov authentication error: #{params[:error]}") | ||
flash[:error] = "There was an issue with logging in. Please try again." | ||
redirect_to new_session_path | ||
end | ||
|
||
if params[:code].nil? && params[:state].nil? | ||
Rails.logger.error("Login.gov unknown error") | ||
flash[:error] = "Please try again." | ||
redirect_to new_session_path | ||
end | ||
end | ||
|
||
def well_known_configuration | ||
@login_gov = LoginGov.new | ||
status, body = @login_gov.get_well_known_configuration | ||
|
||
if status != 200 | ||
Rails.logger.error("well-known/openid-configuration error: code=#{status} - body:\n#{body}") | ||
flash[:error] = "There was an issue logging in." | ||
redirect_to new_session_path | ||
return | ||
end | ||
|
||
Rails.logger.debug("well_known_config response body=#{body}") | ||
@openid_config = body | ||
end | ||
|
||
def decode_token | ||
private_key = @login_gov.private_key | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SessionsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
class LoginGov | ||
|
||
# :acr_value, | ||
# :client_id, | ||
# :idp_host, | ||
# :login_redirect_uri, | ||
# :logout_redirect_uri, | ||
# :logout_uri, | ||
# :private_key_password, | ||
# :private_key_path, | ||
# :token_endpoint, | ||
attr_reader :config | ||
|
||
def initialize(config = Rails.configuration.login_gov_oidc) | ||
@config = config.freeze.dup | ||
end | ||
|
||
def authorization_url | ||
query = { | ||
client_id: config[:client_id], | ||
response_type: "code", | ||
acr_values: config[:acr_value], | ||
scope: "openid email", | ||
redirect_uri: config[:login_redirect_uri], | ||
state: SecureRandom.hex(16), | ||
nonce: SecureRandom.hex(16), | ||
prompt: "select_account" | ||
}.to_query | ||
|
||
"#{config[:idp_host]}/openid_connect/authorize?#{query}" | ||
end | ||
|
||
def logout_url | ||
query = { | ||
client_id: config[:client_id], | ||
post_logout_redirect_uri: config[:logout_redirect_uri] | ||
}.to_query | ||
|
||
"#{config[:logout_uri]}?#{query}" | ||
end | ||
|
||
def well_known_configuration_url | ||
config[:idp_host] + "/.well-known/openid-configuration" | ||
end | ||
|
||
def get_well_known_configuration | ||
response = Faraday.get(well_known_configuration_url) | ||
[response.status, response.body] | ||
end | ||
|
||
def private_key | ||
key_path = config[:private_key_path] | ||
key_pass = config[:private_key_password] | ||
Rails.logger.info("Get private key from .pem file=#{key_path} pass=#{key_pass}") | ||
"🔐" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Session#create</h1> | ||
<p>Find me in app/views/session/create.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Session#delete</h1> | ||
<p>Find me in app/views/session/delete.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="usa-card__container custom-card col-md-6 rules-of-behavior"> | ||
<div class="usa-card__body"> | ||
<div class="rules-wrapper"> | ||
<h2 class="text-center">You must accept the U.S. Government System terms to sign into this website</h2> | ||
<p class="text-center rules-text"> | ||
This is a U.S. General Services Administration Federal Government | ||
computer system that is "FOR OFFICIAL USE ONLY." This System is subject | ||
to monitoring. Individuals found performing unauthorized activities are | ||
subject to disciplinary action including criminal prosecution. | ||
</p> | ||
<%= button_to("Accept and Sign-in", session_path, class: "usa-button center-btn") %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Session#result</h1> | ||
<p>Find me in app/views/session/result.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "test_helper" | ||
|
||
class SessionsControllerTest < ActionDispatch::IntegrationTest | ||
test "should get new" do | ||
get session_new_url | ||
assert_response :success | ||
end | ||
|
||
test "should get create" do | ||
post session_create_url | ||
assert_response :success | ||
end | ||
|
||
test "should get delete" do | ||
get session_delete_url | ||
assert_response :success | ||
end | ||
|
||
test "should get result" do | ||
get session_result_url | ||
assert_response :success | ||
end | ||
end |