omniauth-munic 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/README.md +131 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/omniauth/strategies/munic.rb +37 -0
- data/lib/omniauth-munic/version.rb +5 -0
- data/lib/omniauth-munic.rb +3 -0
- data/omniauth-munic.gemspec +28 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e453c7aa6dbba1c851623524a53ff2fa58c8f13
|
4
|
+
data.tar.gz: 4977c2b7818114704acfec7a2369e1a09b3f3cc1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6bc1f787c006e54ad0a1f1113816a80fc935c6b50f4d11748f9fa25a2fde8eef3e8698dd0a170ec3734071d617fbb40ce28d1d8316f52ae4ae9c6860aea3dec5
|
7
|
+
data.tar.gz: af1ff396de3b034046265a85af95b08e4c4452a29e678bfe666568702c8ee28bebb5975036312646788be646b957ff14b35c7a4254bd345175411719471d2e68
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Omniauth::Munic
|
2
|
+
|
3
|
+
This gem contains the MunicConnect strategy for OmniAuth.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add these lines to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-munic'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install omniauth-munic
|
20
|
+
|
21
|
+
### Register your application on MunicConnect
|
22
|
+
|
23
|
+
First, you need to register your application on MunicConnect. [Here](https://connect.munic.io/oauth/applications) you can create a new application (you need to be logged in with your MunicConnect account).
|
24
|
+
|
25
|
+
* Name : Name of your application
|
26
|
+
* Private : If yes, MunicConnect User must be approved (by you) before be abble to sign in your application; else, any MunicConnect User can sign in.
|
27
|
+
* Authorized users : If your application is private, this allow you to authorize users to acces your application.
|
28
|
+
* Redirect uri : After successfull sign in on MunicConnect, customer will be redirected on your application. E.g. '[yoursite]/auth/munic/callback'. (You will re-use it [here](#routes).)
|
29
|
+
|
30
|
+
### Set Application uid and Secret
|
31
|
+
[Applications](https://connect.munic.io/oauth/applications) is listing all your applications. By clicking on the name of an application, you can get information about it, especially two strings of 64 hexadecimal characters long : "Application" and "Secret". _DO NOT_ share this credentials !
|
32
|
+
|
33
|
+
Put them in `config/initializers/omniauth.rb` like so :
|
34
|
+
|
35
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
36
|
+
provider :munic, 'APPLICATION', 'SECRET'
|
37
|
+
end
|
38
|
+
|
39
|
+
### Routes
|
40
|
+
In `config/routes.rb`, you must `get` the [redirect uri](#register-your-application-on-municconnect) and trigger an action.
|
41
|
+
|
42
|
+
Basically you will need to create a session on your site :
|
43
|
+
|
44
|
+
get 'REDIRECT_URI', to: 'SESSION_CONTROLLER_NAME#create'
|
45
|
+
|
46
|
+
E.g.
|
47
|
+
|
48
|
+
get '/auth/munic/callback', to: 'sessions#create_from_munic'
|
49
|
+
|
50
|
+
|
51
|
+
### Model and Controller
|
52
|
+
|
53
|
+
You have to manage your own Model User and Sessions Controller.
|
54
|
+
Above are examples.
|
55
|
+
|
56
|
+
#### Users Table
|
57
|
+
create_table :users do |t|
|
58
|
+
t.string :provider
|
59
|
+
t.string :uid
|
60
|
+
t.string :email
|
61
|
+
end
|
62
|
+
|
63
|
+
#### User Model
|
64
|
+
def self.create_with_omniauth(auth)
|
65
|
+
create! do |user|
|
66
|
+
user.provider = auth["provider"]
|
67
|
+
user.uid = auth["uid"]
|
68
|
+
user.email = auth["info"].email
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#### Session Controller
|
73
|
+
def create_from_munic
|
74
|
+
auth = request.env["omniauth.auth"]
|
75
|
+
user = User.find_by_provider_and_uid(auth[:provider], auth[:uid]) || User.create_with_omniauth(auth)
|
76
|
+
redirect_to root_url, :notice => "Signed in!"
|
77
|
+
end
|
78
|
+
|
79
|
+
### Link to "Sign in with Munic"
|
80
|
+
<%= link_to "Sign in with Munic", "/auth/munic" %>
|
81
|
+
|
82
|
+
|
83
|
+
### Redirect to exact same point after successfull sign in (optional)
|
84
|
+
In your Session Controller add the following line :
|
85
|
+
|
86
|
+
redirect_to request.env["omniauth.origin"] || root_url, :notice => "Signed in!"
|
87
|
+
|
88
|
+
|
89
|
+
## Usage
|
90
|
+
|
91
|
+
### User's information
|
92
|
+
You can get user's information when [creating a session](#session-controller) with this line :
|
93
|
+
|
94
|
+
auth = request.env["omniauth.auth"]
|
95
|
+
auth["info"]
|
96
|
+
|
97
|
+
You can get :
|
98
|
+
* Email -> auth["info"].email
|
99
|
+
* Full Name -> auth["info"].full_name
|
100
|
+
* Company Name -> auth["info"].company_name if present
|
101
|
+
* Time Zone -> auth["info"].time_zone if present
|
102
|
+
* V.a.t -> auth["info"].vat if present
|
103
|
+
* Language -> auth["info"].language
|
104
|
+
|
105
|
+
### Update User's information
|
106
|
+
If you store information in your database, you may want to update it. This method needs the user to sign-in to update information.
|
107
|
+
|
108
|
+
#### User Model
|
109
|
+
Add this method to your user model :
|
110
|
+
|
111
|
+
def update_info(info)
|
112
|
+
if self.updated_at < info.updated_at
|
113
|
+
self.update_attribute(:email, info.email)
|
114
|
+
#update other information you have stored
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
#### Session Controller
|
119
|
+
Add this line to your session creation :
|
120
|
+
|
121
|
+
def create_from_munic
|
122
|
+
auth = request.env["omniauth.auth"]
|
123
|
+
user = User.find_by_provider_and_uid(auth[:provider], auth[:uid]) || User.create_with_omniauth(auth)
|
124
|
+
user.update_info(auth[:extra][:raw_info]) #
|
125
|
+
redirect_to root_url, :notice => "Signed in!"
|
126
|
+
end
|
127
|
+
|
128
|
+
## Refresh token
|
129
|
+
Please note that the gem does not provide a helper to refresh the access token once it has expried. Each partner application will have to implment it.
|
130
|
+
Please use [munic connect documentation](https://connect.munic.io/docs/api/v1) for implement refresh token fallback.
|
131
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'omniauth-munic'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategies
|
3
|
+
autoload :Munic, 'omniauth/strategies/munic'
|
4
|
+
|
5
|
+
class Munic < OmniAuth::Strategies::OAuth2
|
6
|
+
# Give your strategy a name.
|
7
|
+
option :name, 'munic'
|
8
|
+
|
9
|
+
# This is where you pass the options you would pass when
|
10
|
+
# initializing your consumer from the OAuth gem.
|
11
|
+
option :client_options, {:site => 'https://connect.munic.io'}
|
12
|
+
|
13
|
+
# These are called after authentication has succeeded. If
|
14
|
+
# possible, you should try to set the UID without making
|
15
|
+
# additional calls (if the user id is returned with the token
|
16
|
+
# or as a URI parameter). This may not be possible with all
|
17
|
+
# providers.
|
18
|
+
uid { raw_info['uid'] }
|
19
|
+
|
20
|
+
info do
|
21
|
+
i = {
|
22
|
+
email: raw_info['email'],
|
23
|
+
full_name: raw_info['full_name'],
|
24
|
+
language: raw_info['language']
|
25
|
+
}
|
26
|
+
i[:time_zone] = raw_info['time_zone'] unless raw_info['time_zone'].nil?
|
27
|
+
i[:company] = raw_info['company'] unless raw_info['company'].nil?
|
28
|
+
i[:vat] = raw_info['vat'] unless raw_info['vat'].nil?
|
29
|
+
i
|
30
|
+
end
|
31
|
+
|
32
|
+
def raw_info
|
33
|
+
@raw_info ||= access_token.get('/api/v1/users/me.json').parsed
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-munic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.add_dependency 'omniauth-oauth2', '~> 1.3.1'
|
8
|
+
|
9
|
+
spec.name = 'omniauth-munic'
|
10
|
+
spec.version = OmniAuth::Munic::VERSION
|
11
|
+
spec.authors = ['maxime dufay']
|
12
|
+
spec.email = ['maxime.dufay@mobile-devices.fr']
|
13
|
+
|
14
|
+
spec.description = 'The Munic OAuth2 strategy for OmniAuth 1.x.'
|
15
|
+
spec.summary = spec.description
|
16
|
+
spec.homepage = 'https://github.com/municio/omniauth-munic'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
|
27
|
+
spec.add_development_dependency 'omniauth-oauth2', '~> 1.3.1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-munic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- maxime dufay
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.5.0
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3.5'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.5.0
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: omniauth-oauth2
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.3.1
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.3.1
|
89
|
+
description: The Munic OAuth2 strategy for OmniAuth 1.x.
|
90
|
+
email:
|
91
|
+
- maxime.dufay@mobile-devices.fr
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- Gemfile
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/omniauth-munic.rb
|
103
|
+
- lib/omniauth-munic/version.rb
|
104
|
+
- lib/omniauth/strategies/munic.rb
|
105
|
+
- omniauth-munic.gemspec
|
106
|
+
homepage: https://github.com/municio/omniauth-munic
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: The Munic OAuth2 strategy for OmniAuth 1.x.
|
130
|
+
test_files: []
|