aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-05 21:51:37 +0200
committerhellekin <hellekin@cepheide.org>2020-10-05 21:51:37 +0200
commit48031dde29d6dc4a0ba84c445ae4c07627257d4a (patch)
treefdbe4b896b04ad9e39ebb0b73516b77b61330dd2
parent81fb71f0510a5464634a65d97939f6fa54f419dd (diff)
downloadincommon-map-48031dde29d6dc4a0ba84c445ae4c07627257d4a.tar.gz
Configure Discourse SSO
We're creating a minimal User model that will be filled from SSO. We also configure Inflections so we can use SSO instead of Sso which looks weird for a module named after an acronym. Use Discourse as SSO: https://meta.discourse.org/t/using-discourse-as-a-sso-provider/32974
-rw-r--r--app/lib/sso.rb2
-rw-r--r--app/lib/sso/from_discourse.rb3
-rw-r--r--app/models/user.rb4
-rw-r--r--config/initializers/inflections.rb6
-rw-r--r--config/initializers/session_store.rb6
-rw-r--r--config/initializers/sso_config.rb2
-rw-r--r--db/migrate/20201005154823_create_users.rb15
7 files changed, 37 insertions, 1 deletions
diff --git a/app/lib/sso.rb b/app/lib/sso.rb
index ace2830..0939a7c 100644
--- a/app/lib/sso.rb
+++ b/app/lib/sso.rb
@@ -5,3 +5,5 @@ module SSO
require 'securerandom'
require_relative '../../config/initializers/sso_config'
end
+
+
diff --git a/app/lib/sso/from_discourse.rb b/app/lib/sso/from_discourse.rb
index 66742e2..a5df192 100644
--- a/app/lib/sso/from_discourse.rb
+++ b/app/lib/sso/from_discourse.rb
@@ -2,7 +2,8 @@
module SSO
class FromDiscourse
- attr_accessor :nonce, :token, :user_info, :status
+ attr_accessor :nonce, :token
+ attr_reader :request_uri, :user_info, :status
class << self
# See config/initializers/sso.rb
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..f7e96a8
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,4 @@
+class User < ApplicationRecord
+ has_many :agencies
+ has_many :agents, through: :agencies, source: :agent
+end
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
index ac033bf..13e8739 100644
--- a/config/initializers/inflections.rb
+++ b/config/initializers/inflections.rb
@@ -14,3 +14,9 @@
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end
+
+ActiveSupport::Inflector.inflections do |inflect|
+ inflect.irregular 'human', 'humans'
+ inflect.acronym 'API'
+ inflect.acronym 'SSO'
+end
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb
new file mode 100644
index 0000000..4af1519
--- /dev/null
+++ b/config/initializers/session_store.rb
@@ -0,0 +1,6 @@
+if Rails.env.production?
+ # Only serve session cookies over HTTPS
+ Rails.application.config.session_store :cookie_store, key: 'map_session', expire_after: 7.days, httponly: true, secure: true
+else
+ Rails.application.config.session_store :cookie_store, key: 'map_session', expire_after: 7.days
+end
diff --git a/config/initializers/sso_config.rb b/config/initializers/sso_config.rb
index b3f23f7..f5413ff 100644
--- a/config/initializers/sso_config.rb
+++ b/config/initializers/sso_config.rb
@@ -9,6 +9,8 @@
# end
# end
+require 'sso/from_discourse'
+
SSO::FromDiscourse.config = {
sso_url: 'https://talk.incommon.cc/session/sso_provider',
return_url: "http://localhost:3000/authenticate",
diff --git a/db/migrate/20201005154823_create_users.rb b/db/migrate/20201005154823_create_users.rb
new file mode 100644
index 0000000..2d8403c
--- /dev/null
+++ b/db/migrate/20201005154823_create_users.rb
@@ -0,0 +1,15 @@
+class CreateUsers < ActiveRecord::Migration[6.0]
+ def change
+ create_table :users do |t|
+ t.string :name
+ t.string :username
+ t.string :email
+ t.bigint :external_id
+ t.string :avatar_url
+
+ t.timestamps
+ end
+ add_index :users, [:external_id], unique: true
+ add_index :users, [:email], unique: true
+ end
+end