[REN] Renamed the module to auth_oauth2_provider

bzr revid: fme@openerp.com-20120926113102-pdhpz9zh6zirrapw
This commit is contained in:
Fabien Meghazi
2012-09-26 13:31:02 +02:00
parent 4536fe76ca
commit 5e3a747290
13 changed files with 172 additions and 8 deletions
@@ -20,7 +20,7 @@
##############################################################################
import controllers
import res_users
import auth_oauth2_provider
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -21,21 +21,20 @@
{
'name': 'OAuth Provider',
'name': 'OAuth2 Provider',
'version': '0.1',
'category': 'Tools',
'description': """
Allow an openerp server to provide partial OAuth service.
=========================================================
Allow an openerp server to provide OAuth2 authentication service.
=================================================================
""",
'author': 'OpenERP s.a.',
'maintainer': 'OpenERP s.a.',
'website': 'http://www.openerp.com',
'depends': ['base', 'web'],
#'data': ['res_users.xml'],
'js': ['static/src/js/oauth_provider.js'],
'css': ['static/src/css/oauth_provider.css'],
'qweb': ['static/src/xml/oauth_provider.xml'],
'js': ['static/src/js/auth_oauth2_provider.js'],
'css': ['static/src/css/auth_oauth2_provider.css'],
'qweb': ['static/src/xml/auth_oauth2_provider.xml'],
'installable': True,
'auto_install': False,
}
@@ -0,0 +1,64 @@
#!/usr/bin/env python
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2012 OpenERP s.a. (<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/>.
#
##############################################################################
from openerp.osv import osv, fields
import uuid
class res_users(osv.osv):
"""Oauth2 Provider Class"""
_inherit = 'res.users'
_columns = {
# TODO: partial implementation supporting only one client_id for the moment.
'last_oauth_token': fields.char('Last OAuth Token', size=32, readonly=True, invisible=True),
'last_oauth_token_scope': fields.char('Last OAuth Token Scope', readonly=True, invisible=True),
}
def auth_oauth_provider_get_token(self, cr, uid, client_id="", scope="", context=None):
token = str(uuid.uuid4()).replace('-', '')
self.write(cr, uid, [uid], {
"last_oauth_token": token,
"last_oauth_token_scope": scope,
}, context=context)
return token
def auth_oauth_provider_tokeninfo(self, cr, uid, access_token, context=None):
user_id = self.search(cr, uid, [('last_oauth_token', '=', access_token)], context=context)
if len(user_id) != 1:
return {
"error": "invalid_token"
}
user = self.browse(cr, uid, user_id[0], context=context)
if access_token == user.last_oauth_token:
r = {
"user_id": user.id,
"scope": user.last_oauth_token_scope,
#"audience": "8819981768.apps.googleusercontent.com",
#"expires_in": 436
}
if user.partner_id.email: # TODO: should deliver only according to scopes
r['email'] = user.partner_id.email
return r
else:
return {
"error": "invalid_token"
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,14 @@
@charset "utf-8";
.openerp .oe_oauth_provider {
padding: 0 10px;
}
.openerp .oe_oauth_provider .oe_oauth_provider_error span.oe_i {
font-size: 60px;
color: #990000;
float: left;
}
.openerp .oe_oauth_provider .oe_oauth_provider_error ul {
list-style: none;
float: left;
font-weight: bold;
}
@@ -0,0 +1,17 @@
@charset "utf-8"
.openerp .oe_oauth_provider
padding: 0 10px
.oe_oauth_provider_error
span.oe_i
font-size: 60px
color: #900
float: left
ul
list-style: none
float: left
font-weight: bold
// au BufWritePost,FileWritePost *.sass :!sass --style expanded --line-numbers <afile> > "%:p:r.css"
// vim:tabstop=4:shiftwidth=4:softtabstop=4:fdm=marker:
@@ -0,0 +1,70 @@
openerp.auth_oauth_provider = function(instance) {
var QWeb = instance.web.qweb;
var _t = instance.web._t;
instance.web.client_actions.add('oauth2_auth', 'instance.auth_oauth_provider.ProviderAction');
instance.auth_oauth_provider.ProviderAction = instance.web.Widget.extend({
template: "auth_oauth_provider",
start: function (parent) {
var self = this;
this._super.apply(this, arguments);
var params = $.deparam($.param.querystring());
if (params.response_type !== 'token') {
this.error(_t("Unsupported 'response_type' parameter"));
}
if (!params.redirect_uri) {
this.error(_t("No 'redirect_uri' parameter given"));
}
// params.client_id
// TODO: check if client_id application is authorized to use the service, and get it's name
// that should be displayed in the approval confirmation dialog.
if (!this._error) {
// params.approval_prompt TODO --> add 'none' (default)
// TODO: get client_id and scope
this.$('.oe_oauth_provider_approval').show().on('click', '.oe_oauth_provider_allow', function() {
instance.session.rpc('/oauth2/get_token', {
client_id: params.client_id || '',
scope: params.scope || '',
}).then(function(result) {
self.redirect(result);
}).fail(function() {
self.error(_t("An error occured while contacting the OpenERP server."));
});
}).on('click', '.oe_oauth_provider_deny', function() {
self.redirect({
error: 'access_denied'
});
});
}
},
redirect: function(result) {
var params = $.deparam($.param.querystring());
var a = document.createElement('a');
a.href = params.redirect_uri;
var new_params = {};
if (!result.error) {
new_params.access_token = result.access_token;
new_params.token_type = 'Bearer';
if (result.expires_in) {
new_params.expires_in = result.expires_in;
}
} else {
new_params.error = result.error;
}
if (params.state) {
new_params.state = params.state;
}
var redirect = params.redirect_uri + (a.hash ? '&' : '#') + $.param(new_params);
window.location = redirect;
},
error: function(msg) {
this._error = true;
var $msg = $('<li/>').addClass('oe_oauth_provider_error_text').text(msg);
$msg.appendTo(this.$('.oe_oauth_provider_error').show().find('ul'));
return false;
},
});
};