Skip to content

Commit 7d81a7a

Browse files
cycomacheadclaude
authored andcommitted
feat: switch 'log in with snap' provider to Snap!Cloud
Replaces the Discourse forum SSO provider with Snap!Cloud's SSO endpoint. Since Snap!Cloud implements the same Discourse SSO protocol, this change updates the configuration URLs and environment variables while maintaining backward compatibility for the SSO secret. - Update SSO URL to point to snap.berkeley.edu API - Introduce OSEM_SNAP_SSO_SECRET and OSEM_SNAP_SSO_URL env vars - Fix provider detection logic to only require a secret for Discourse - Remove outdated "log in twice" UI warning - Add Discourse mock authentication for development and testing Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent c75f8dc commit 7d81a7a

6 files changed

Lines changed: 27 additions & 10 deletions

File tree

app/helpers/users_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def omniauth_configured
1414

1515
providers = []
1616
Devise.omniauth_providers.each do |provider|
17+
# Discourse SSO (Snap!Cloud) only requires a secret, not a key
18+
if provider == :discourse
19+
providers << provider if ENV.fetch('OSEM_SNAP_SSO_SECRET', ENV.fetch('OSEM_DISCOURSE_SECRET', nil)).present?
20+
next
21+
end
22+
1723
provider_key = "#{provider}_key"
1824
provider_secret = "#{provider}_secret"
1925
unless Rails.application.secrets.send(provider_key).blank? || Rails.application.secrets.send(provider_secret).blank?

app/views/devise/shared/_openid_links.html.haml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,3 @@
1616
Snap
1717
%em> !
1818
%br
19-
.text-center
20-
%em If you are not currently logged into Snap! or the Snap! Forums, you will need to log in to
21-
Snap!Con twice when using your Snap! account. We're working on fixing this. Thanks!
22-
23-
%br

config/environments/development.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@
131131
secret: 'github_mock_secret'
132132
}
133133
)
134+
135+
OmniAuth.config.mock_auth[:discourse] =
136+
OmniAuth::AuthHash.new(
137+
provider: 'discourse',
138+
uid: 'discourse-test-uid-1',
139+
info: {
140+
name: 'snap user',
141+
email: 'user-snap@example.com',
142+
username: 'user_snap'
143+
}
144+
)
145+
134146
config.after_initialize do
135147
Devise.setup do |devise_config|
136148
# Enable ichain test mode

config/initializers/devise.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
name: 'google',
1515
scope: %w[email profile]
1616

17-
# TODO-SNAPCON: This ought to be configurable. Use OSEM_DISCOURSE_KEY?
1817
config.omniauth :discourse,
19-
sso_url: 'https://forum.snap.berkeley.edu/session/sso_provider',
20-
sso_secret: ENV.fetch('OSEM_DISCOURSE_SECRET', nil)
18+
sso_url: ENV.fetch('OSEM_SNAP_SSO_URL', 'https://snap.berkeley.edu/api/v1/discourse-sso'),
19+
sso_secret: ENV.fetch('OSEM_SNAP_SSO_SECRET', ENV.fetch('OSEM_DISCOURSE_SECRET', nil))
2120

2221
config.omniauth :facebook,
2322
ENV.fetch('OSEM_FACEBOOK_KEY', Rails.application.secrets.facebook_key),

dotenv.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
# OSEM_GITHUB_KEY=1234
6868
# OSEM_GITHUB_SECRET=5678
6969

70+
# Snap!Cloud SSO (Discourse SSO protocol)
71+
# The shared secret must match the DISCOURSE_SSO_SECRET configured in Snap!Cloud
72+
# OSEM_SNAP_SSO_SECRET=your_shared_secret
73+
# Optionally override the SSO endpoint URL (defaults to https://snap.berkeley.edu/api/v1/discourse-sso)
74+
# OSEM_SNAP_SSO_URL=https://snap.berkeley.edu/api/v1/discourse-sso
75+
7076
# OMNIAUTH Developer KEY/Secret for SUSE/openSUSE
7177
# OSEM_SUSE_KEY=1234
7278
# OSEM_SUSE_SECRET=5678

spec/support/omniauth_macros.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ module OmniauthMacros
1212
ENV['OSEM_SUSE_SECRET'] = 'test secret suse'
1313
ENV['OSEM_GITHUB_KEY'] = 'test key github'
1414
ENV['OSEM_GITHUB_SECRET'] = 'test secret github'
15-
ENV['OSEM_DISCOURSE_KEY'] = 'test key discourse'
16-
ENV['OSEM_DISCOURSE_SECRET'] = 'test secret discourse'
15+
ENV['OSEM_SNAP_SSO_SECRET'] = 'test secret snap sso'
1716

1817
def mock_auth_new_user
1918
OmniAuth.config.mock_auth[:google] =

0 commit comments

Comments
 (0)