Skip to content

Commit

Permalink
Using osm.org as identity provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mmd-osm committed Aug 13, 2024
1 parent 7cd7db5 commit 5c17e12
Show file tree
Hide file tree
Showing 8 changed files with 404 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ gem "omniauth-google-oauth2", ">= 0.6.0"
gem "omniauth-mediawiki", ">= 0.0.4"
gem "omniauth-microsoft_graph"
gem "omniauth-openid"
gem "omniauth_openid_connect"
gem "omniauth-rails_csrf_protection", "~> 1.0"

# Doorkeeper for OAuth2
Expand Down
50 changes: 50 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
aes_key_wrap (1.1.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
argon2 (2.3.0)
ffi (~> 1.15)
ffi-compiler (~> 1.0)
ast (2.4.2)
attr_required (1.0.2)
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
aws-eventstream (1.3.0)
Expand Down Expand Up @@ -123,6 +125,7 @@ GEM
parser (>= 2.4)
smart_properties
bigdecimal (3.1.8)
bindata (2.5.0)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
bootsnap (1.18.4)
Expand Down Expand Up @@ -219,6 +222,8 @@ GEM
dry-initializer (~> 3.0)
dry-schema (>= 1.12, < 2)
zeitwerk (~> 2.6)
email_validator (2.2.4)
activemodel
erb_lint (0.6.0)
activesupport
better_html (>= 2.0.1)
Expand All @@ -237,6 +242,8 @@ GEM
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.1.1)
net-http
ffi (1.17.0)
Expand Down Expand Up @@ -302,6 +309,13 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.7.2)
json-jwt (1.16.6)
activesupport (>= 4.2)
aes_key_wrap
base64
bindata
faraday (~> 2.0)
faraday-follow_redirects
jwt (2.8.2)
base64
kgio (2.11.4)
Expand Down Expand Up @@ -402,6 +416,22 @@ GEM
omniauth-rails_csrf_protection (1.0.2)
actionpack (>= 4.2)
omniauth (~> 2.0)
omniauth_openid_connect (0.8.0)
omniauth (>= 1.9, < 3)
openid_connect (~> 2.2)
openid_connect (2.3.0)
activemodel
attr_required (>= 1.0.0)
email_validator
faraday (~> 2.0)
faraday-follow_redirects
json-jwt (>= 1.16)
mail
rack-oauth2 (~> 2.2)
swd (~> 2.0)
tzinfo
validate_url
webfinger (~> 2.0)
openstreetmap-deadlock_retry (1.3.1)
parallel (1.26.2)
parser (3.3.4.2)
Expand All @@ -420,6 +450,13 @@ GEM
rack (2.2.9)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-oauth2 (2.2.1)
activesupport
attr_required
faraday (~> 2.0)
faraday-follow_redirects
json-jwt (>= 1.11.0)
rack (>= 2.1.0)
rack-openid (1.4.2)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
Expand Down Expand Up @@ -566,6 +603,11 @@ GEM
strong_migrations (1.8.0)
activerecord (>= 5.2)
strscan (3.1.0)
swd (2.0.3)
activesupport (>= 3)
attr_required (>= 0.0.5)
faraday (~> 2.0)
faraday-follow_redirects
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
terser (1.2.3)
Expand All @@ -581,11 +623,18 @@ GEM
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (0.13.0)
validate_url (1.0.15)
activemodel (>= 3.0.0)
public_suffix
validates_email_format_of (1.8.2)
i18n (>= 0.8.0)
simpleidn
vendorer (0.2.0)
version_gem (1.1.4)
webfinger (2.1.3)
activesupport
faraday (~> 2.0)
faraday-follow_redirects
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
Expand Down Expand Up @@ -670,6 +719,7 @@ DEPENDENCIES
omniauth-microsoft_graph
omniauth-openid
omniauth-rails_csrf_protection (~> 1.0)
omniauth_openid_connect
openstreetmap-deadlock_retry (>= 1.3.1)
pg
puma (~> 5.6)
Expand Down
323 changes: 323 additions & 0 deletions app/assets/images/auth_providers/openstreetmap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def auth_success
when "openid"
uid.match(%r{https://www.google.com/accounts/o8/id?(.*)}) ||
uid.match(%r{https://me.yahoo.com/(.*)})
when "google", "facebook", "microsoft", "github", "wikipedia"
when "google", "facebook", "microsoft", "github", "wikipedia", "openstreetmap"
true
else
false
Expand Down
15 changes: 15 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@
microsoft_options = { :name => "microsoft", :scope => "openid User.Read" }
github_options = { :name => "github", :scope => "user:email" }
wikipedia_options = { :name => "wikipedia", :client_options => { :site => "https://meta.wikimedia.org" } }
osm_oidc_options = { :name => :openstreetmap,
:scope => [Settings.openstreetmap_auth_scopes, :openid].flatten.compact.uniq.map(&:to_sym),
:issuer => "https://www.openstreetmap.org",
:discovery => true,
:response_type => :code,
:uid_field => "preferred_username",
:client_options => {
:port => 443,
:scheme => "https",
:host => "www.openstreetmap.org",
:identifier => Settings.openstreetmap_auth_id,
:secret => Settings.openstreetmap_auth_secret,
:redirect_uri => format("%<protocol>s://%<server_url>s/auth/openstreetmap/callback", :protocol => Settings.server_protocol, :server_url => Settings.server_url)
} }

google_options[:openid_realm] = Settings.google_openid_realm if Settings.key?(:google_openid_realm)

Rails.application.config.middleware.use OmniAuth::Builder do
provider :openid, openid_options
provider :openid_connect, osm_oidc_options
provider :google_oauth2, Settings.google_auth_id, Settings.google_auth_secret, google_options if Settings.key?(:google_auth_id)
provider :facebook, Settings.facebook_auth_id, Settings.facebook_auth_secret, facebook_options if Settings.key?(:facebook_auth_id)
provider :microsoft_graph, Settings.microsoft_auth_id, Settings.microsoft_auth_secret, microsoft_options if Settings.key?(:microsoft_auth_id)
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ en:
microsoft: Microsoft
github: GitHub
wikipedia: Wikipedia
openstreetmap: OpenStreetMap
api:
notes:
comment:
Expand Down Expand Up @@ -2612,6 +2613,9 @@ en:
wikipedia:
title: Log in with Wikipedia
alt: Wikipedia logo
openstreetmap:
title: Log in with OpenStreetMap
alt: OpenStreetMap logo
oauth:
authorize:
title: "Authorize access to your account"
Expand Down
9 changes: 9 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ fossgis_valhalla_url: "https://valhalla1.openstreetmap.de/route"
#microsoft_auth_secret: ""
#wikipedia_auth_id: ""
#wikipedia_auth_secret: ""

# Settings to use osm.org production as identity provider
# Requires confidential OAuth2 app on osm.org with scope "openid"
# and callback http(s)://{other site}/auth/openstreetmap/callback
#openstreetmap_auth_id: ""
#openstreetmap_auth_secret: ""
# Define additional scopes (openid scope is included by default)
#openstreetmap_auth_scopes: ["read_email", "skip_authorization"]

# Thunderforest authentication details
#thunderforest_key: ""
# Tracestrack authentication details
Expand Down
1 change: 1 addition & 0 deletions lib/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def self.providers
providers[I18n.t("auth.providers.microsoft")] = "microsoft" if Settings.key?(:microsoft_auth_id)
providers[I18n.t("auth.providers.github")] = "github" if Settings.key?(:github_auth_id)
providers[I18n.t("auth.providers.wikipedia")] = "wikipedia" if Settings.key?(:wikipedia_auth_id)
providers[I18n.t("auth.providers.openstreetmap")] = "openstreetmap" if Settings.key?(:openstreetmap_auth_id)
end.freeze
end
end

0 comments on commit 5c17e12

Please sign in to comment.