-
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.
Add Okta authentication and a home page
- Loading branch information
Showing
9 changed files
with
114 additions
and
2 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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
class ApplicationController < ActionController::Base | ||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. | ||
allow_browser versions: :modern | ||
|
||
before_action :authenticate_user | ||
|
||
protected | ||
|
||
def signed_in? | ||
session[:id_token].present? | ||
end | ||
|
||
def authenticate_user | ||
unless signed_in? | ||
redirect_to new_session_path | ||
end | ||
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,4 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
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,38 @@ | ||
class SessionsController < ApplicationController | ||
skip_before_action :authenticate_user | ||
def new | ||
redirect_to root_path if signed_in? | ||
end | ||
|
||
def create | ||
unless okta_signed_in? | ||
redirect_to new_session_path, | ||
flash: {error: "Sorry, the okta login failed."} | ||
return | ||
end | ||
|
||
session[:id_token] = omniauth.dig("extra", "id_token") | ||
session[:omniauth_hash] = omniauth | ||
redirect_to root_path | ||
end | ||
|
||
def destroy | ||
id_token = session[:id_token] | ||
session.clear | ||
if id_token.present? | ||
redirect_to "#{ENV.fetch("OKTA_ISSUER")}/v1/logout?id_token_hint=#{id_token}&post_logout_redirect_uri=#{request.base_url}", allow_other_host: true | ||
else | ||
redirect_to root_path | ||
end | ||
end | ||
|
||
private | ||
|
||
def okta_signed_in? | ||
omniauth&.extra&.raw_info&.email.present? | ||
end | ||
|
||
def omniauth | ||
@omniauth ||= request.env["omniauth.auth"] | ||
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 @@ | ||
Placeholder for the home page. |
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,15 @@ | ||
<!-- because of https://github.com/omniauth/omniauth/wiki/Resolving-CVE-2015-9284, we need to do a post to /auth/oktaoauth, so this page will do it seamlessly without being visible to the user --> | ||
<html> | ||
<head> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', (event) => { | ||
document.getElementById('auth_form').submit(); | ||
}) | ||
</script> | ||
</head> | ||
|
||
<body> | ||
<%= form_tag "/auth/oktaoauth", id: "auth_form" do %> | ||
<% end %> | ||
</body> | ||
</html> |
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