diff --git a/addons/auth_oauth_signup/__init__.py b/addons/auth_oauth_signup/__init__.py new file mode 100644 index 00000000000..bc40c87d118 --- /dev/null +++ b/addons/auth_oauth_signup/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2012-today OpenERP SA () +# +# 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 +# +############################################################################## + +import res_users diff --git a/addons/auth_oauth_signup/__openerp__.py b/addons/auth_oauth_signup/__openerp__.py new file mode 100644 index 00000000000..1e5767065a4 --- /dev/null +++ b/addons/auth_oauth_signup/__openerp__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2012 OpenERP SA (). +# +# 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 . +# +############################################################################## + +{ + '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, +} diff --git a/addons/auth_oauth_signup/res_users.py b/addons/auth_oauth_signup/res_users.py new file mode 100644 index 00000000000..8b56585d04d --- /dev/null +++ b/addons/auth_oauth_signup/res_users.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-2012 OpenERP SA (). +# +# 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 . +# +############################################################################## + +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 diff --git a/addons/auth_oauth_signup/static/src/js/auth_oauth_signup.js b/addons/auth_oauth_signup/static/src/js/auth_oauth_signup.js new file mode 100644 index 00000000000..6715943af9b --- /dev/null +++ b/addons/auth_oauth_signup/static/src/js/auth_oauth_signup.js @@ -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; + }, + }); + +};