[ADD] auth_oauth_signup: link module to make auth_oauth work with auth_signup
bzr revid: rco@openerp.com-20121126105242-4a1urt7lwnkvchgm
This commit is contained in:
parent
867a84c3f8
commit
1299315111
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2012-today OpenERP SA (<http://www.openerp.com>)
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
import res_users
|
|
@ -0,0 +1,39 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2010-2012 OpenERP SA (<http://openerp.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'Signup with OAuth2 Authentication',
|
||||||
|
'version': '1.0',
|
||||||
|
'category': 'Hidden',
|
||||||
|
'description': """
|
||||||
|
Allow users to sign up through OAuth2 Provider.
|
||||||
|
===============================================
|
||||||
|
""",
|
||||||
|
'author': 'OpenERP SA',
|
||||||
|
'website': 'http://www.openerp.com',
|
||||||
|
'depends': ['auth_oauth', 'auth_signup'],
|
||||||
|
'data': [],
|
||||||
|
'js': ['static/src/js/auth_oauth_signup.js'],
|
||||||
|
'css': [],
|
||||||
|
'qweb': [],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': True,
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2010-2012 OpenERP SA (<http://openerp.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import urllib
|
||||||
|
import urlparse
|
||||||
|
import urllib2
|
||||||
|
import simplejson
|
||||||
|
|
||||||
|
import openerp
|
||||||
|
from openerp.osv import osv, fields
|
||||||
|
from openerp import SUPERUSER_ID
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class res_users(osv.Model):
|
||||||
|
_inherit = 'res.users'
|
||||||
|
|
||||||
|
def _auth_oauth_signin(self, cr, uid, provider, validation, params, context=None):
|
||||||
|
# overridden to use signup method if regular oauth signin fails
|
||||||
|
try:
|
||||||
|
login = super(res_users, self)._auth_oauth_signin(cr, uid, provider, validation, params, context=context)
|
||||||
|
|
||||||
|
except openerp.exceptions.AccessDenied:
|
||||||
|
state = simplejson.loads(params['state'])
|
||||||
|
token = state.get('t')
|
||||||
|
oauth_uid = validation['user_id']
|
||||||
|
email = validation.get('email', 'provider_%d_user_%d' % (provider, oauth_uid))
|
||||||
|
name = validation.get('name', email)
|
||||||
|
values = {
|
||||||
|
'name': name,
|
||||||
|
'login': email,
|
||||||
|
'email': email,
|
||||||
|
'oauth_provider_id': provider,
|
||||||
|
'oauth_uid': oauth_uid,
|
||||||
|
'oauth_access_token': params['access_token'],
|
||||||
|
'active': True,
|
||||||
|
}
|
||||||
|
_, login, _ = self.signup(cr, uid, values, token, context=context)
|
||||||
|
|
||||||
|
return login
|
|
@ -0,0 +1,14 @@
|
||||||
|
openerp.auth_oauth_signup = function(instance) {
|
||||||
|
|
||||||
|
// override Login._oauth_state to add the signup token in the state
|
||||||
|
instance.web.Login.include({
|
||||||
|
_oauth_state: function(provider) {
|
||||||
|
var state = this._super.apply(this, arguments);
|
||||||
|
if (this.params.token) {
|
||||||
|
state.t = this.params.token;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue