omniauth-magento 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +86 -0
- data/Rakefile +1 -0
- data/lib/omniauth/magento.rb +2 -0
- data/lib/omniauth/magento/version.rb +5 -0
- data/lib/omniauth/strategies/magento.rb +33 -0
- data/omniauth-magento.gemspec +21 -0
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35ecc46b30899582767672d0d2547d9f99af3653
|
4
|
+
data.tar.gz: dcd44bb8bdd75b1cb0475448fe1bc534a5712d33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9f9fc91ec0b3ce347ade68b46946aff9cf958cadea69c838055332fbbc2ce0a5fb53b5fe062918f0a58a0f12d753dd13f34c4bc42bb033b5b5b478f91d61283
|
7
|
+
data.tar.gz: a1112d61860c8e5a691c08d3fde8c69bac25673099854bcc8e43b8241c1de3306d1d7443496943e98453188057a94424fa54f923880a9c1a347e321f8c4f4398
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Omniauth::Magento
|
2
|
+
|
3
|
+
An Omniauth strategy for Magento. Works only with the newer Magento REST api (not SOAP).
|
4
|
+
|
5
|
+
## Instructions on how to use with Rails
|
6
|
+
|
7
|
+
### Setting up Magento
|
8
|
+
|
9
|
+
* [Set up a consumer in Magento](http://www.magentocommerce.com/api/rest/authentication/oauth_configuration.html) and write down consumer key and consumer secret
|
10
|
+
* In the Magento Admin backend, go to `System > Web Services > REST Roles`, select `Customer`, and tick `Retrieve` under `Customer`
|
11
|
+
* In the Magento Admin backend, go to `System > Web Services > REST Attributes`, select `Customer`, and tick `Email`, `First name` and `Last name` under `Customer` > `Read`.
|
12
|
+
|
13
|
+
### Setting up Rails
|
14
|
+
|
15
|
+
Parts of these instructions are based on these [OmniAuth instructions](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview), which you can read in case you get stuck.
|
16
|
+
|
17
|
+
* Install [Devise](https://github.com/plataformatec/devise) if you haven't installed it
|
18
|
+
* Load this library into your Gemfile: `gem "omniauth-magento", github: "Zookal/omniauth-magento"`
|
19
|
+
* Run `bundle install`
|
20
|
+
* Modify `config/initializers/devise.rb`:
|
21
|
+
|
22
|
+
```
|
23
|
+
Devise.setup do |config|
|
24
|
+
# deactivate SSL on development environment
|
25
|
+
OpenSSL::SSL::VERIFY_PEER ||= OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
|
26
|
+
config.omniauth :magento, ENTER_YOUR_MAGENTO_CONSUMER_KEY, ENTER_YOUR_MAGENTO_CONSUMER_SECRET, { :client_options => { :site => ENTER_YOUR_MAGENTO_URL_WITHOUT_TRAILING_SLASH } }
|
27
|
+
# example:
|
28
|
+
# config.omniauth :magento, "12a3", "45e6", { :client_options => { :site => "http://localhost/magento" } }
|
29
|
+
```
|
30
|
+
|
31
|
+
* Make sure you have the columns `first_name`, `last_name`, `magento_id` and `email` in your `User` table
|
32
|
+
* Add this line to your view `<%= link_to "Sign in with Magento", user_omniauth_authorize_path(:magento) %>`
|
33
|
+
* Add / replace this line in your `routes.rb` `devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }`. This will be called once Magento has successfully authorized and returns to the Rails app.
|
34
|
+
* In your folder `controllers`, create a subfolder `users`
|
35
|
+
* In that subfolder `app/controllers/users/`, create a file `omniauth_callbacks_controller.rb` with the following code (from Devise wiki linked above):
|
36
|
+
|
37
|
+
```
|
38
|
+
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
39
|
+
def magento
|
40
|
+
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
41
|
+
@user = User.find_for_magento_oauth(request.env["omniauth.auth"], current_user)
|
42
|
+
|
43
|
+
if @user.persisted?
|
44
|
+
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
|
45
|
+
set_flash_message(:notice, :success, :kind => "magento") if is_navigational_format?
|
46
|
+
else
|
47
|
+
session["devise.magento_data"] = request.env["omniauth.auth"]
|
48
|
+
redirect_to new_user_registration_url
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
* Set up your User model to be omniauthable `:omniauthable, :omniauth_providers => [:magento]` and to contain the `find_for_magento_oauth` method (from Devise wiki linked above)
|
55
|
+
|
56
|
+
```
|
57
|
+
class User < ActiveRecord::Base
|
58
|
+
devise :database_authenticatable, :registerable, :recoverable,
|
59
|
+
:rememberable, :trackable, :validatable, :timeoutable,
|
60
|
+
:omniauthable, :omniauth_providers => [:magento]
|
61
|
+
|
62
|
+
def self.find_for_magento_oauth(auth, signed_in_resource=nil)
|
63
|
+
user = User.find_by(magento_id: auth.uid)
|
64
|
+
unless user
|
65
|
+
user = User.create!(
|
66
|
+
first_name: auth.info.first_name,
|
67
|
+
last_name: auth.info.last_name,
|
68
|
+
magento_id: auth.uid,
|
69
|
+
email: auth.info.email,
|
70
|
+
password: Devise.friendly_token[0,20]
|
71
|
+
)
|
72
|
+
end
|
73
|
+
user
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Authenticating
|
79
|
+
|
80
|
+
* Start your Rails server
|
81
|
+
* Start your Magento server
|
82
|
+
* Log into Magento with a customer (not admin) account
|
83
|
+
* In your Rails app, go to the view where you pasted this line `<%= link_to "Sign in with Magento", user_omniauth_authorize_path(:magento) %>`
|
84
|
+
* Click on the link
|
85
|
+
* You now should be directed to a Magento view where you are prompted to authorize access to the Magento user account
|
86
|
+
* Once you have confirmed, you should get logged into Rails and redirected to the callback URL specified above. The User model should also create a database entry when the user logs in for the first time.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'omniauth/strategies/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Magento < OmniAuth::Strategies::OAuth
|
7
|
+
option :name, "magento"
|
8
|
+
|
9
|
+
option :client_options, {
|
10
|
+
:access_token_path => "/oauth/token",
|
11
|
+
:authorize_path => "/oauth/authorize",
|
12
|
+
:request_token_path => "/oauth/initiate",
|
13
|
+
}
|
14
|
+
|
15
|
+
# set uid
|
16
|
+
uid { raw_info.keys.first.to_i }
|
17
|
+
|
18
|
+
# set additional info
|
19
|
+
info do
|
20
|
+
{
|
21
|
+
'first_name' => raw_info.values.first["firstname"],
|
22
|
+
'last_name' => raw_info.values.first["lastname"],
|
23
|
+
'email' => raw_info.values.first["email"]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# get info about current user
|
28
|
+
def raw_info
|
29
|
+
@raw_info ||= MultiJson.decode(access_token.get('/api/rest/customers').body)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth/magento/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'omniauth-magento'
|
8
|
+
spec.version = Omniauth::Magento::VERSION
|
9
|
+
spec.summary = 'Omniauth strategy for Magento'
|
10
|
+
spec.homepage = 'https://github.com/Zookal/omniauth-magento'
|
11
|
+
spec.email = "michael@zookal.com"
|
12
|
+
spec.authors = ['Chris Baynes', 'Daniel Mahlow', 'Michael Imstepf']
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split("\n")
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
spec.add_runtime_dependency 'omniauth-oauth', '~> 1.0'
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-magento
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Baynes
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-12-
|
13
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -59,7 +59,15 @@ email: michael@zookal.com
|
|
59
59
|
executables: []
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
|
-
files:
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/omniauth/magento.rb
|
68
|
+
- lib/omniauth/magento/version.rb
|
69
|
+
- lib/omniauth/strategies/magento.rb
|
70
|
+
- omniauth-magento.gemspec
|
63
71
|
homepage: https://github.com/Zookal/omniauth-magento
|
64
72
|
licenses:
|
65
73
|
- MIT
|