Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 165cd38

Browse files
authoredApr 14, 2025··
Merge pull request #139 from solidusio-contrib/revert-127
Revert #129 and #127 due to security implications
2 parents 9c0ed09 + 01c3307 commit 165cd38

File tree

47 files changed

+216
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+216
-625
lines changed
 

‎Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
source 'https://rubygems.org'
44
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
55

6-
solidus_branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7-
gem 'solidus', github: 'solidusio/solidus', branch: solidus_branch
6+
branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7+
gem 'solidus', github: 'solidusio/solidus', branch: branch
88

99
# The solidus_frontend gem has been pulled out since v3.2
1010
gem 'solidus_frontend'

‎README.md

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ SolidusSocial
66

77
Social login support for Solidus. Solidus Social handles authorization, account
88
creation and association through third-party services.
9-
Currently Google, Facebook, Github and X (formely Twitter) are available out of the box.
10-
Support for Apple ID and Microsoft (Entra and O365) might be offered down the road.
9+
Currently Facebook, Github and Google OAuth2 are available out of the box.
1110

1211
Installation
1312
------------
@@ -26,15 +25,12 @@ bundle exec rails g solidus_social:install
2625
bundle exec rails db:migrate
2726
```
2827

29-
Preference(optional): By default the login path will be `/users/auth/:provider`. If you wish to modify the url to:
30-
`/member/auth/:provider`, `/profile/auth/:provider`, or `/auth/:provider` then you can do this accordingly in
31-
your **config/initializers/spree.rb** file as described below:
28+
This will install a new initializer `config/initializers/solidus_social.rb` into
29+
your project that allows you to setup the services you want configured for your app.
30+
31+
Optional: By default the login path will be '/users/auth/:provider'. If you
32+
want something else, configure it in `config/initializers/solidus_social.rb`.
3233

33-
```ruby
34-
Spree::SocialConfig[:path_prefix] = 'member' # for /member/auth/:provider
35-
Spree::SocialConfig[:path_prefix] = 'profile' # for /profile/auth/:provider
36-
Spree::SocialConfig[:path_prefix] = '' # for /auth/:provider
37-
```
3834

3935
Using OAuth Sources
4036
-------------------
@@ -43,29 +39,12 @@ Login as an admin user and navigate to Configuration > Social Authentication Met
4339

4440
Click "New Authentication Method" and choose one of your configured providers.
4541

46-
Click on the New Authentication Method button to enter the key obtained from their respective source, (See below for instructions on setting up the various providers).
47-
48-
Multiple key entries can now be entered based on the rails environment. This allows for portability and the lack of need to check in your key to your repository. You also have the ability to enable and disable sources. These setting will be reflected on the client UI as well.
49-
50-
Alternatively you can ship keys as environment variables and create these Authentication Method records on application boot via an initializer. Below is an example for facebook.
51-
52-
```ruby
53-
# Ensure our environment is bootstrapped with a facebook connect app
54-
if ActiveRecord::Base.connection.data_source_exists? 'spree_authentication_methods'
55-
Spree::AuthenticationMethod.where(environment: Rails.env, provider: 'facebook').first_or_create do |auth_method|
56-
auth_method.api_key = ENV['FACEBOOK_APP_ID']
57-
auth_method.api_secret = ENV['FACEBOOK_APP_SECRET']
58-
auth_method.active = true
59-
end
60-
end
61-
```
62-
6342
**You MUST restart your application after configuring or updating an authentication method.**
6443

6544
Registering Your Application
6645
----------------------------
6746

68-
OAuth Applications @ Facebook, Twitter, Google and / or Github are supported out of the
47+
Facebook, Github and Google OAuth2 are supported out of the
6948
box but, you will need to register your application with each of the sites you
7049
want to use.
7150

@@ -107,46 +86,72 @@ Make sure you specifity the right IP address.
10786

10887
> More info: [https://developers.google.com/identity/protocols/OAuth2](https://developers.google.com/identity/protocols/OAuth2)
10988
110-
### Twitter
111-
[Twitter / Application Management / Create an application](https://docs.x.com/resources/fundamentals/authentication/oauth-2-0/overview)
89+
### Other OAuth Providers
11290

113-
1. Name and Description must be filled in with something
114-
2. Configure user authentication setting with:
115-
- App permissions: Read (default) and enable Request email from users option.
116-
- Application Website: http://your_computer.local:3000 for development / http://your-site.com for production
117-
- Application Type: Web App, Automated App or Bot
118-
- Callback URL: http://your_computer.local:3000 for development / http://your-site.com for production
119-
3. Save Application
91+
Other OAuth providers are supported, given that there is an [OmniAuth
92+
strategy][12] for them. (If there isn't, you can [write one][13].)
12093

121-
### Adding other OAuth sources
94+
#### LinkedIn Example
12295

123-
It is easy to add any OAuth source, given there is an OmniAuth strategy gem for it (and if not, you can easily write one by yourself). For instance, if you want to add authorization via LinkedIn, the steps will be:
124-
1. Add gem `"omniauth-linkedin"` to your Gemfile, run `bundle install`.
125-
2. In an initializer file, e.g. `config/initializers/devise.rb`, add and init a new provider for SolidusSocial:
96+
1. Add `gem "omniauth-linkedin"` to your Gemfile and run `bundle install`.
97+
2. In `config/initializers/solidus_social.rb` add and initialize a new provider
98+
for SolidusSocial:
12699

127-
**Optional:** If you want to skip the sign up phase where the user has to provide an email and a password, add a third parameter to the provider entry and the Spree user will be created directly using the email field in the [Auth Hash Schema](https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema):
100+
```ruby
128101

129-
```ruby
130-
Provider = Struct.new(:title, :key, :skip_signup)
131-
SolidusSocial::OAUTH_PROVIDERS << Provider.new("LinkedIn", "linkedin", true)
132-
SolidusSocial.init_provider('linkedin')
133-
```
134-
3. Activate your provider as usual (via initializer or admin interface).
102+
config.providers = {
103+
# The configuration key has to match your omniauth strategy.
104+
linkedin: {
105+
api_key: ENV['LINKEDIN_API_KEY'],
106+
api_secret: ENV['LINKEDIN_API_SECRET'],
107+
},
108+
# More providers here
109+
```
110+
3. Activate your provider as usual.
135111
4. Do **one** of the following:
136112

137-
- For legacy frontend, override the `spree/users/social` view to render OAuth links to display
138-
your LinkedIn link and for starter frontend override `spree/starter_frontend/shared/social`.
113+
- Override the `spree/users/social` view to render OAuth links to display
114+
your LinkedIn link.
139115
- Include in your CSS a definition for `.icon-spree-linkedin-circled` and an
140-
embedded icon font for LinkedIn from [Fontello](12) (the way existing
116+
embedded icon font for LinkedIn from [Fontello][14] (the way existing
141117
icons for Facebook etc are implemented). You can also override
142118
CSS classes for other providers, `.icon-spree-<provider>-circled`, to use
143119
different font icons or classic background images, without having to
144120
override views.
145121

122+
#### Apple Id Example
123+
124+
1. Add `gem "omniauth-apple"` to your Gemfile and run `bundle install`.
125+
2. In `config/initializers/solidus_social.rb` add and initialize a new provider
126+
for SolidusSocial:
127+
128+
```ruby
129+
130+
config.providers = {
131+
apple: {
132+
icon: 'fa-apple',
133+
title: 'Apple'
134+
},
135+
# More providers here
136+
```
137+
add its configuration after `SolidusSocial.init_providers` line:
138+
```ruby
139+
140+
Devise.setup do |config|
141+
# The configuration key has to match your omniauth strategy.
142+
config.omniauth :apple, ENV['APPLE_CLIENT_ID'], '',
143+
scope: 'email',
144+
team_id: ENV['APPLE_TEAM_ID'],
145+
key_id: ENV['APPLE_KEY_ID'],
146+
pem: ENV['APPLE_PRIVATE_KEY'].gsub('\n', "\n")
147+
end
148+
```
149+
Notice: APPLE_PRIVATE_KEY should consist from one-line p8-file content, like this `'\n-----BEGIN PRIVATE KEY-----\nsecret\n-----END PRIVATE KEY-----\n'`
150+
146151
Documentation
147152
-------------
148153

149-
API documentation is available [on RubyDoc.info][13].
154+
API documentation is available [on RubyDoc.info][15].
150155

151156
Contributing
152157
------------

0 commit comments

Comments
 (0)
Please sign in to comment.