Skip to content

Commit

Permalink
Merge pull request #36 from GSA/CP-9-login-gov
Browse files Browse the repository at this point in the history
[9] connect and configure login.gov openid connect
  • Loading branch information
stepchud authored Jul 31, 2024
2 parents 30c3de9 + 1d91475 commit 0ea9404
Show file tree
Hide file tree
Showing 19 changed files with 491 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ commands:
steps:
- run: bundle exec rake db:setup

build_assets:
description: 'Install yarn modules and build assets'
steps:
- node/install:
install-yarn: true
- node/install-packages:
pkg-manager: yarn
- run: npx gulp copyAssets
- run: npx gulp compile
- run: yarn build
- run: yarn build:css

jobs:
checkout_code:
executor:
Expand Down Expand Up @@ -59,6 +71,8 @@ jobs:

- prepare_database

- build_assets

- run:
name: Run Tests
command: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/private.pem
/config/public.crt

/app/assets/builds/*
!/app/assets/builds/.keep
Expand Down
20 changes: 19 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ gem "pg"
# Use the Puma web server [https://github.com/puma/puma]
gem "puma", ">= 5.0"

# Use the popular Faraday HTTP library
gem "faraday"

# Use the JWT gem for JSON Web Tokens
gem "jwt"

# Use simple asset pipeline
gem "propshaft", "~> 0.9.0"
gem "cssbundling-rails", "~> 1.4"
Expand Down Expand Up @@ -49,8 +55,18 @@ group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri windows]

gem "rubocop"
gem "rspec-rails"

# add the Ruby LSP package so it's bundled with the rest of the gems and available to VS Code
gem "ruby-lsp"

# rubocop and specific extensions used by VS Code
gem "rubocop"
gem "rubocop-performance", require: false
gem "rubocop-rake", require: false
gem "rubocop-rails", require: false
gem "rubocop-rspec", require: false

gem "codeclimate-test-reporter"
end

Expand All @@ -70,8 +86,10 @@ end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "webmock"
gem "capybara"
gem "selenium-webdriver"
gem "rspec_junit_formatter"
gem "simplecov"
gem "rails-controller-testing"
end
52 changes: 52 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ GEM
simplecov (<= 0.13)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
Expand All @@ -111,9 +114,15 @@ GEM
docile (1.1.5)
drb (2.2.1)
erubi (1.13.0)
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-net_http (3.1.0)
net-http
foreman (0.88.1)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.0)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
Expand All @@ -126,6 +135,8 @@ GEM
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json (2.7.2)
jwt (2.8.2)
base64
language_server-protocol (3.17.0.3)
logger (1.6.0)
loofah (2.22.0)
Expand All @@ -142,6 +153,8 @@ GEM
minitest (5.24.1)
msgpack (1.7.2)
mutex_m (0.2.0)
net-http (0.4.1)
uri
net-imap (0.4.14)
date
net-protocol
Expand All @@ -165,6 +178,7 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.6)
prism (0.30.0)
propshaft (0.9.0)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
Expand Down Expand Up @@ -198,6 +212,10 @@ GEM
activesupport (= 7.1.3.4)
bundler (>= 1.15.0)
railties (= 7.1.3.4)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
Expand All @@ -215,6 +233,8 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rbs (3.5.2)
logger
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.2)
Expand Down Expand Up @@ -254,6 +274,23 @@ GEM
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.25.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.0.3)
rubocop (~> 1.61)
ruby-lsp (0.17.9)
language_server-protocol (~> 3.17.0)
prism (>= 0.29.0, < 0.31)
rbs (>= 3, < 4)
sorbet-runtime (>= 0.5.10782)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.23.0)
Expand All @@ -267,6 +304,7 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sorbet-runtime (0.5.11492)
stimulus-rails (1.3.3)
railties (>= 6.0.0)
stringio (3.1.1)
Expand All @@ -280,11 +318,16 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket (1.2.11)
websocket-driver (0.7.6)
Expand All @@ -309,22 +352,31 @@ DEPENDENCIES
codeclimate-test-reporter
cssbundling-rails (~> 1.4)
debug
faraday
foreman
jbuilder
jsbundling-rails (~> 1.3)
jwt
pg
propshaft (~> 0.9.0)
puma (>= 5.0)
rails (~> 7.1.3, >= 7.1.3.4)
rails-controller-testing
rspec-rails
rspec_junit_formatter
rubocop
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
ruby-lsp
selenium-webdriver
simplecov
stimulus-rails
turbo-rails
tzinfo-data
web-console
webmock

RUBY VERSION
ruby 3.2.4p170
Expand Down
58 changes: 58 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

class SessionsController < ApplicationController
before_action :check_error_result, :require_code_param, :exchange_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
# TODO: store the user_info in the session
# session[:user_info] = @login_userinfo
end

private

def check_error_result
return unless params[:error]

Rails.logger.error("Login.gov authentication error: #{params[:error]}")
flash[:error] = t("login_error")
redirect_to new_session_path
end

def require_code_param
return if params[:code].present?

Rails.logger.error("Login.gov unknown error")
flash[:error] = t("please_try_again")
redirect_to new_session_path
end

# Authenticates a user with login.gov using JWT
def exchange_token
login_gov = LoginGov.new
@login_userinfo = login_gov.exchange_token_from_auth_result(params[:code])
Rails.logger.debug do
"userinfo=#{@login_userinfo}"
end
rescue LoginGov::LoginApiError => e
Rails.logger.error("LoginGov::LoginApiError(#{e.message}) status(#{e.status_code}):\n#{e.response_body}")
flash[:error] = t("login_error")
redirect_to new_session_path
end
end
Loading

0 comments on commit 0ea9404

Please sign in to comment.