Added google and linked in authentication.

This commit is contained in:
Martin Edenhofer 2012-04-18 13:26:59 +02:00
parent c5dee5c797
commit 1c250b586c
9 changed files with 240 additions and 118 deletions

View file

@ -26,6 +26,7 @@ gem "omniauth"
gem "omniauth-twitter"
gem "omniauth-facebook"
gem "omniauth-linkedin"
gem "omniauth-google-oauth2"
gem "twitter"
gem "koala"

View file

@ -83,6 +83,9 @@ GEM
rack
omniauth-facebook (1.2.0)
omniauth-oauth2 (~> 1.0.0)
omniauth-google-oauth2 (0.1.9)
omniauth (~> 1.0)
omniauth-oauth2
omniauth-linkedin (0.0.6)
omniauth-oauth (~> 1.0.0)
omniauth-oauth (1.0.0)
@ -160,6 +163,7 @@ DEPENDENCIES
mime-types
omniauth
omniauth-facebook
omniauth-google-oauth2
omniauth-linkedin
omniauth-twitter
rails (= 3.2.2)

View file

@ -182,14 +182,19 @@ class App.Controller extends Spine.Controller
if attribute.tag is 'boolean'
# build options list
if _.isEmpty(attribute.options)
attribute.options = [
{ name: 'active', value: true }
{ name: 'inactive', value: false }
] || []
]
# update boolean types
for record in attribute.options
record.value = '{boolean}::' + record.value
# finde selected item of list
for record in attribute.options
if record.value is attribute.value
if record.value is '{boolean}::' + attribute.value
record.selected = 'selected'
# return item
@ -286,6 +291,15 @@ class App.Controller extends Spine.Controller
else
param[key.name].push key.value
else
# check boolean
boolean = key.value.split '::'
if boolean[0] is '{boolean}'
if boolean[1] is 'true'
key.value = true
else
key.value = false
param[key.name] = key.value
@log 'formParam', form, param

View file

@ -28,6 +28,11 @@ class Index extends App.Controller
name: 'LinkedIn',
config: 'auth_linkedin',
},
google_oauth2: {
url: '/auth/google_oauth2',
name: 'Google',
config: 'auth_google_oauth2',
},
}
auth_providers = []
for key, provider of auth_provider_all

View file

@ -7,6 +7,8 @@ require 'user_info'
# load omniauth strategies with database lookups api keys at runtime
require 'twitter_database'
require 'facebook_database'
require 'linked_in_database'
require 'google_oauth2_database'
# Initialize the rails application
Zammad::Application.initialize!

View file

@ -1,13 +1,17 @@
Rails.application.config.middleware.use OmniAuth::Builder do
# twitter database connect
provider :twitter_database, 'xx', 'xx',
provider :twitter_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse',
:client_options => { :authorize_path => '/oauth/authorize', :site => 'https://api.twitter.com' }
# facebook database connect
provider :facebook_database, 'xx', 'xx'
provider :facebook_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse'
# linkedin database connect
# provider :linked_in_database, 'xx', 'xx'
provider :linked_in_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse'
# google database connect
provider :google_oauth2_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse',
:authorize_options => { :access_type => 'online', :approval_prompt => '' }
end

View file

@ -157,16 +157,16 @@ Setting.create(
:display => '',
:null => true,
:name => 'user_create_account',
:tag => 'select',
:tag => 'boolean',
:options => {
1 => 'yes',
0 => 'no',
true => 'yes',
false => 'no',
},
},
],
},
:state => {
:value => 1,
:value => true,
},
:frontend => true
)
@ -181,16 +181,16 @@ Setting.create(
:display => '',
:null => true,
:name => 'user_lost_password',
:tag => 'select',
:tag => 'boolean',
:options => {
1 => 'yes',
0 => 'no',
true => 'yes',
false => 'no',
},
},
],
},
:state => {
:value => 1,
:value => true,
},
:frontend => true
)
@ -205,16 +205,16 @@ Setting.create(
:display => '',
:null => true,
:name => 'switch_to_user',
:tag => 'select',
:tag => 'boolean',
:options => {
1 => 'yes',
0 => 'no',
true => 'yes',
false => 'no',
},
},
],
},
:state => {
:value => 0,
:value => false,
},
:frontend => true
)
@ -229,16 +229,16 @@ Setting.create(
:display => '',
:null => true,
:name => 'auth_db',
:tag => 'select',
:tag => 'boolean',
:options => {
1 => 'yes',
0 => 'no',
true => 'yes',
false => 'no',
},
},
],
},
:state => {
:value => 1,
:value => true,
},
:frontend => true
)
@ -253,7 +253,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'auth_twitter',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -303,7 +303,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'auth_facebook',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -343,6 +343,58 @@ Setting.create(
},
:frontend => false
)
Setting.create(
:title => 'Autentication via Google',
:name => 'auth_google_oauth2',
:area => 'Security::Authentication',
:description => 'Enables user authentication via Google.',
:options => {
:form => [
{
:display => '',
:null => true,
:name => 'auth_google_oauth2',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
},
},
],
},
:state => {
:value => false,
},
:frontend => true
)
Setting.create(
:title => 'Google App Credentials',
:name => 'auth_google_oauth2_credentials',
:area => 'Security::Authentication',
:description => 'Enables user authentication via Google.',
:options => {
:form => [
{
:display => 'Client ID',
:null => true,
:name => 'client_id',
:tag => 'input',
},
{
:display => 'Client Secret',
:null => true,
:name => 'client_secret',
:tag => 'input',
},
],
},
:state => {
:value => {},
},
:frontend => false
)
Setting.create(
:title => 'Autentication via LinkedIn',
:name => 'auth_linkedin',
@ -354,7 +406,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'auth_linkedin',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -661,7 +713,7 @@ Setting.create(
:display => 'Checksum',
:null => true,
:name => 'checksum',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -723,7 +775,7 @@ Setting.create(
:display => 'Checksum',
:null => true,
:name => 'checksum',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -803,7 +855,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'customer_ticket_create',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -828,7 +880,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'customer_ticket_view',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',
@ -985,7 +1037,7 @@ Setting.create(
:display => '',
:null => true,
:name => 'chat',
:tag => 'select',
:tag => 'boolean',
:options => {
true => 'yes',
false => 'no',

View file

@ -0,0 +1,20 @@
module OmniAuth
module Strategies
class GoogleOauth2Database < OmniAuth::Strategies::GoogleOauth2
option :name, 'google_oauth2'
def initialize(app, *args, &block)
# database lookup
puts 'GoogleOauth2Database -> initialize'
config = Setting.get('auth_google_oauth2_credentials') || {}
args[0] = config['client_id']
args[1] = config['client_secret']
super
end
end
end
end

20
lib/linked_in_database.rb Normal file
View file

@ -0,0 +1,20 @@
module OmniAuth
module Strategies
class LinkedInDatabase < OmniAuth::Strategies::LinkedIn
option :name, 'linkedin'
def initialize(app, *args, &block)
# database lookup
puts 'LinkedInDatabase -> initialize'
config = Setting.get('auth_linkedin_credentials') || {}
args[0] = config['app_id']
args[1] = config['app_secret']
super
end
end
end
end