strongmind-auth 1.0.2 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 739e3ce6d5b6705f2079e7a24b572d21df94d8e3509a487a30f427ce22254713
4
- data.tar.gz: f338629c41d5ec042f11e8627d852fd388738fcbe0f4fd61d0fb085b20a2e380
3
+ metadata.gz: c354a11e582f73dbffa8303b9f62da41ba670ab4b149521bc449b21136721b97
4
+ data.tar.gz: 240af831cd266936721d98f8e8a0796cd7700d8722d8e2dcf7bc62e5b78d7f8c
5
5
  SHA512:
6
- metadata.gz: 1214dd5316b2402c75c41d10b74dce2cede5c639bcf72e84b78faf1de325b186d60bc57edd186678e14f4e26bf01f101334e37a317c95432e7d9854ed248be85
7
- data.tar.gz: 662dd22e6c058e7022e3a1f872ec097ab688019959afb030ac9529617c18771da14f2b4774c071729229d681e47706a97fa8f9e8cf77b641a7060e329c4d37dc
6
+ metadata.gz: c2f44a55c2cece8baacf95d9cda467e4ab4d5c1a93cee41b0f1c7e9b7f4efce42111571c05ae303e8e46cedd31f6673b236f7a00d0dc5cb0262cd4ecc262f0e3
7
+ data.tar.gz: 9b5ed691d3d9e850f17fec2ba0af08012e046236c56efd37df46b1d0a3dd2dfc2a4f98caff8a42ab29f676d4861e65bf9b67d50fc206a4348a55e1f50dcf22c9
data/README.md CHANGED
@@ -2,13 +2,17 @@
2
2
 
3
3
  Ruby gem for authentication in a rails app
4
4
 
5
- ## Usage
5
+ ## Creating a new Rails app
6
6
 
7
- 1. `rails new app_name --css tailwind`
8
- 1. `bundle add strongmind-auth`
9
- 1. `rails g strongmind:install`
10
- 1. Move app root to authenticated root in routes
11
- 1. Add `IDENTITY_CLIENT_ID` and `IDENTITY_CLIENT_SECRET` values to .env
12
- 1. `bundle`
13
- 1. `rails dev:cache`
14
- 1. `bin/dev`
7
+ 1. Use [Repository Dashboard](https://repository-dashboard.strongmind.com/repositories/new) to create a new repository
8
+ with the rails-template.
9
+ 1. Navigate to the repo folder in a terminal and execute `rails g strongmind:install`
10
+ 1. Move app root to authenticated root in routes. Should look like this:
11
+ ```ruby
12
+ authenticated :user do
13
+ root to: 'home#index' # or whatever makes sense for your app
14
+ end
15
+ ```
16
+ 1. Create a new client in identity server and `IDENTITY_CLIENT_ID` and `IDENTITY_CLIENT_SECRET` values to .env file.
17
+ 1. Execute `rails dev:cache` to turn on caching in development.
18
+ 1. Execute `bin/dev`
@@ -0,0 +1,26 @@
1
+ require 'platform_sdk'
2
+
3
+ module StrongMindNav
4
+ extend ActiveSupport::Concern
5
+
6
+ def fetch_common_nav
7
+ begin
8
+ navbar = PlatformSdk::CommonNavFetcher.new(current_user, request).retrieve(menu_items)
9
+
10
+ @top_navbar_html = navbar[:top_navbar_html]
11
+ @bottom_navbar_html = navbar[:bottom_navbar_html]
12
+ @theme_css = navbar[:theme_css]
13
+ rescue PlatformSdk::CommonNavFetcher::TokenNotFoundError, PlatformSdk::CommonNavFetcher::UserNotFoundError
14
+ render 'logins/index'
15
+ rescue Faraday::TimeoutError
16
+ @top_navbar_html = render_to_string(partial: 'layouts/loading_navbar').html_safe
17
+ end
18
+ end
19
+
20
+ def menu_items
21
+ [
22
+ { name: 'Home', icon: 'fa-solid fa-house', path_method: :root_path }
23
+ ]
24
+ end
25
+
26
+ end
@@ -1,5 +1,6 @@
1
1
  class LoginsController < ApplicationController
2
2
  skip_before_action :authenticate_user!
3
+ skip_before_action :fetch_common_nav
3
4
 
4
5
  def index
5
6
  flash[:alert] = nil
@@ -3,6 +3,7 @@
3
3
  module Users
4
4
 
5
5
  class OmniauthCallbacksController < Devise::OmniauthCallbacksController
6
+ skip_before_action :fetch_common_nav
6
7
 
7
8
  def strongmind
8
9
  auth = request.env['omniauth.auth']
@@ -0,0 +1,30 @@
1
+ <a href="/" data-turbo="false">
2
+ <nav class="flex sm-top-nav">
3
+ <div class="flex-1 branding-container">
4
+ <img class="branding-logo-lg" src="https://prod-backpack-ui.strongmind.com/assets/images/sm-logo-2c-white.png"/>
5
+ <img class="branding-logo-sm" src="https://prod-backpack-ui.strongmind.com/assets/images/SMbulb.svg"/>
6
+ </div>
7
+
8
+ <div id="loading">
9
+ <canvas id="canvas" width="64" height="64"></canvas>
10
+
11
+ <script src="https://unpkg.com/@rive-app/canvas@2.9.3"></script>
12
+ <script>
13
+ const r = new rive.Rive({
14
+ src: "https://backpack.strongmind.com/assets/images/loader_dark_mode.riv",
15
+ canvas: document.getElementById("canvas"),
16
+ autoplay: true,
17
+ stateMachines: null,
18
+ onLoad: () => {
19
+ },
20
+ });
21
+ </script>
22
+ </div>
23
+
24
+ <div class="flex-1 justify-end sm-top-nav-controls">
25
+ <div class="profile-container">
26
+ <i class="fa-light fa-circle-user text-white fa-2xl"></i>
27
+ </div>
28
+ </div>
29
+ </nav>
30
+ </a>
@@ -276,9 +276,11 @@ Devise.setup do |config|
276
276
  # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
277
277
  identity_base_url = ENV['IDENTITY_BASE_URL'] || "https://devlogin.strongmind.com"
278
278
  app_base_url = ENV['APP_BASE_URL'] || "http://localhost:3000"
279
+ scopes = %i[openid profile offline_access]
280
+ scopes = scopes + ENV['IDENTITY_SCOPES'].split(' ').map(&:to_sym) if ENV['IDENTITY_SCOPES'].present?
279
281
  config.omniauth :openid_connect, {
280
282
  name: :strongmind,
281
- scope: %i[openid profile],
283
+ scope: scopes,
282
284
  response_type: :code,
283
285
  issuer: identity_base_url,
284
286
  discovery: true,
@@ -11,9 +11,16 @@ module Strongmind
11
11
  copy_file "user.rb", "app/models/user.rb", force: true
12
12
  end
13
13
 
14
- def protect_app_files
14
+ def protect_app_files_and_add_nav
15
15
  inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base\n" do
16
- " before_action :authenticate_user!\n"
16
+ " include StrongMindNav\n before_action :authenticate_user!\n before_action :fetch_common_nav\n
17
+ # Implement the list of menu items for the application
18
+ # def menu_items
19
+ # [
20
+ # { name: 'Home', icon: 'fa-solid fa-house', path_method: :root_path }
21
+ # ]
22
+ # end"
23
+
17
24
  end
18
25
  end
19
26
 
@@ -51,6 +58,7 @@ devise_scope :user do
51
58
  def add_dotenv_file
52
59
  copy_file "env", ".env"
53
60
  end
61
+
54
62
  end
55
63
 
56
64
  end
@@ -1,4 +1,8 @@
1
1
  IDENTITY_CLIENT_ID=
2
2
  IDENTITY_CLIENT_SECRET=
3
+
4
+ # Space delimited list of scopes
5
+ IDENTITY_SCOPES=
6
+
3
7
  IDENTITY_BASE_URL=https://devlogin.strongmind.com
4
8
  APP_BASE_URL=http://localhost:3000
@@ -1,5 +1,5 @@
1
1
  module Strongmind
2
2
  module Auth
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongmind-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Belding
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-12 00:00:00.000000000 Z
11
+ date: 2024-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -105,13 +105,14 @@ files:
105
105
  - Rakefile
106
106
  - app/assets/config/strongmind_auth_manifest.js
107
107
  - app/assets/stylesheets/strongmind/auth/application.css
108
+ - app/controllers/concerns/strong_mind_nav.rb
108
109
  - app/controllers/logins_controller.rb
109
110
  - app/controllers/users/omniauth_callbacks_controller.rb
110
111
  - app/helpers/strongmind/auth/application_helper.rb
111
112
  - app/jobs/rails/auth/application_job.rb
112
113
  - app/mailers/rails/auth/application_mailer.rb
113
114
  - app/models/user_base.rb
114
- - app/views/layouts/strongmind/auth/application.html.erb
115
+ - app/views/layouts/_loading_navbar.html.erb
115
116
  - app/views/logins/index.html.erb
116
117
  - config/initializers/devise.rb
117
118
  - config/routes.rb
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Rails auth</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%#= stylesheet_link_tag "strongmind/auth/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>