Do not send an oauth token expiry time
[cds-indico.git] / indico / modules / oauth / __init__.py
blobd4055d4bed8949873dee49c4a1c41fd348380e84
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from __future__ import unicode_literals
19 import os
20 from datetime import timedelta
22 from flask_oauthlib.provider import OAuth2Provider
24 from indico.core import signals
25 from indico.core.logger import Logger
26 from indico.util.i18n import _
27 from indico.web.flask.util import url_for
28 from indico.web.menu import MenuItem
31 class IndicoOAuth2Provider(OAuth2Provider):
32 def init_app(self, app):
33 app.config.setdefault('OAUTH2_PROVIDER_TOKEN_EXPIRES_IN', int(timedelta(days=3650).total_seconds()))
34 super(IndicoOAuth2Provider, self).init_app(app)
37 oauth = IndicoOAuth2Provider()
38 logger = Logger.get('oauth')
41 @signals.admin_sidemenu.connect
42 def _extend_admin_menu(sender, **kwargs):
43 from MaKaC.webinterface.wcomponents import SideMenuItem
44 return 'applications', SideMenuItem('Applications', url_for('oauth.apps'))
47 @signals.users.profile_sidemenu.connect
48 def _extend_profile_menu(user, **kwargs):
49 return MenuItem(_('Applications'), 'oauth.user_profile')
52 @signals.app_created.connect
53 def _no_ssl_required_on_debug(app, **kwargs):
54 if app.debug:
55 os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = 'true'
58 @signals.users.merged.connect
59 def _delete_merged_user_tokens(target, source, **kwargs):
60 source.oauth_tokens.delete()
61 logger.info("All tokens for the user {} were deleted.".format(source))