# Path: invenio_oauthclient/ext.py
# class InvenioOAuthClientREST(object):
#     """Invenio Oauthclient extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization."""
#         if app:
#             self._state = self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization."""
#         _default_response_handler = obj_or_import_string(
#             app.config.get("OAUTHCLIENT_REST_DEFAULT_RESPONSE_HANDLER"),
#             handlers.rest.default_response_handler
#         )
#         _default_remote_handler = handlers.rest.default_remote_response_handler
#         state = _OAuthClientState(
#             app, 'OAUTHCLIENT_REST_REMOTE_APPS',
#             handlers.rest.disconnect_handler,
#             handlers.rest.authorized_default_handler,
#             default_remote_app_response_handler=_default_remote_handler,
#             default_response_handler=_default_response_handler
#         )
# 
#         app.extensions['invenio-oauthclient'] = state
#         return state
# 
# Path: invenio_oauthclient/contrib/orcid.py
# class ORCIDOAuthSettingsHelper(OAuthSettingsHelper):
#     def __init__(self, title=None, description=None, base_url=None,
#                  app_key=None, access_token_url=None, authorize_url=None,
#                  precedence_mask=None):
#     def get_handlers(self):
#     def get_rest_handlers(self):
# def account_info(remote, resp):
# def _disconnect(remote, *args, **kwargs):
# def disconnect_handler(remote, *args, **kwargs):
# def disconnect_rest_handler(remote, *args, **kwargs):
# def account_setup(remote, token, resp):
# BASE_APP = _orcid_app.base_app
# REMOTE_APP = _orcid_app.remote_app
# REMOTE_REST_APP = _orcid_app.remote_rest_app
# REMOTE_MEMBER_APP = _orcid_member_app.remote_app
# REMOTE_SANDBOX_APP = _orcid_sandbox_app.remote_app
# REMOTE_SANDBOX_REST_APP = _orcid_sandbox_app.remote_rest_app
# REMOTE_SANDBOX_MEMBER_APP = _orcid_sandbox_member_app.remote_app
# 
# Path: invenio_oauthclient/views/client.py
# def post_ext_init(state):
# def auto_redirect_login(*args, **kwargs):
# def _login(remote_app, authorized_view_name):
# def login(remote_app):
# def rest_login(remote_app):
# def _authorized(remote_app=None):
# def authorized(remote_app=None):
# def rest_authorized(remote_app=None):
# def _signup(remote_app):
# def signup(remote_app):
# def rest_signup(remote_app):
# def _disconnect(remote_app):
# def disconnect(remote_app):
# def rest_disconnect(remote_app):
# 
# Path: invenio_oauthclient/_compat.py
# def monkey_patch_werkzeug():
#     """Patch top level removed modules."""
#     try:
#         from werkzeug import cached_property
#     except ImportError:
#         werkzeug.cached_property = werkzeug.utils.cached_property
#         werkzeug.parse_options_header = werkzeug.http.parse_options_header
#         werkzeug.url_quote = werkzeug.urls.url_quote
#         werkzeug.url_decode = werkzeug.urls.url_decode
#         werkzeug.url_encode = werkzeug.urls.url_encode


import os
from flask import Flask, redirect, url_for
from flask_babelex import Babel
from flask_login import current_user
from flask_menu import Menu as FlaskMenu
from invenio_accounts import InvenioAccounts
from invenio_accounts.views import blueprint as blueprint_user
from invenio_db import InvenioDB
from invenio_mail import InvenioMail as Mail
from invenio_userprofiles import InvenioUserProfiles
from invenio_userprofiles.views import \
    blueprint_api_init as blueprint_userprofile_api_init
from invenio_userprofiles.views import \
    blueprint_ui_init as blueprint_userprofile_ui_init
from invenio_oauthclient import InvenioOAuthClientREST
from invenio_oauthclient.contrib import orcid
from invenio_oauthclient.views.client import rest_blueprint as blueprint_client
from invenio_oauthclient._compat import monkey_patch_werkzeug  # noqa isort:skip
from flask_oauthlib.client import OAuth as FlaskOAuth  # noqa isort:skip

   .. code-block:: console

       $ ./app-teardown.sh

SPHINX-END

"""




monkey_patch_werkzeug()  # noqa isort:skip


# [ Configure application credentials ]
ORCID_APP_CREDENTIALS = dict(
    consumer_key=os.environ.get('ORCID_APP_CREDENTIALS_KEY'),
    consumer_secret=os.environ.get('ORCID_APP_CREDENTIALS_SECRET'),
)

# Create Flask application
app = Flask(__name__)

app.config.update(
    SQLALCHEMY_ECHO=False,
    SQLALCHEMY_DATABASE_URI=os.environ.get(
        'SQLALCHEMY_DATABASE_URI', 'sqlite:///orcid_app_rest.db'
    ),
    OAUTHCLIENT_REST_REMOTE_APPS=dict(

# Path: invenio_oauthclient/ext.py
# class InvenioOAuthClientREST(object):
#     """Invenio Oauthclient extension."""
# 
#     def __init__(self, app=None):
#         """Extension initialization."""
#         if app:
#             self._state = self.init_app(app)
# 
#     def init_app(self, app):
#         """Flask application initialization."""
#         _default_response_handler = obj_or_import_string(
#             app.config.get("OAUTHCLIENT_REST_DEFAULT_RESPONSE_HANDLER"),
#             handlers.rest.default_response_handler
#         )
#         _default_remote_handler = handlers.rest.default_remote_response_handler
#         state = _OAuthClientState(
#             app, 'OAUTHCLIENT_REST_REMOTE_APPS',
#             handlers.rest.disconnect_handler,
#             handlers.rest.authorized_default_handler,
#             default_remote_app_response_handler=_default_remote_handler,
#             default_response_handler=_default_response_handler
#         )
# 
#         app.extensions['invenio-oauthclient'] = state
#         return state
# 
# Path: invenio_oauthclient/contrib/orcid.py
# class ORCIDOAuthSettingsHelper(OAuthSettingsHelper):
#     def __init__(self, title=None, description=None, base_url=None,
#                  app_key=None, access_token_url=None, authorize_url=None,
#                  precedence_mask=None):
#     def get_handlers(self):
#     def get_rest_handlers(self):
# def account_info(remote, resp):
# def _disconnect(remote, *args, **kwargs):
# def disconnect_handler(remote, *args, **kwargs):
# def disconnect_rest_handler(remote, *args, **kwargs):
# def account_setup(remote, token, resp):
# BASE_APP = _orcid_app.base_app
# REMOTE_APP = _orcid_app.remote_app
# REMOTE_REST_APP = _orcid_app.remote_rest_app
# REMOTE_MEMBER_APP = _orcid_member_app.remote_app
# REMOTE_SANDBOX_APP = _orcid_sandbox_app.remote_app
# REMOTE_SANDBOX_REST_APP = _orcid_sandbox_app.remote_rest_app
# REMOTE_SANDBOX_MEMBER_APP = _orcid_sandbox_member_app.remote_app
# 
# Path: invenio_oauthclient/views/client.py
# def post_ext_init(state):
# def auto_redirect_login(*args, **kwargs):
# def _login(remote_app, authorized_view_name):
# def login(remote_app):
# def rest_login(remote_app):
# def _authorized(remote_app=None):
# def authorized(remote_app=None):
# def rest_authorized(remote_app=None):
# def _signup(remote_app):
# def signup(remote_app):
# def rest_signup(remote_app):
# def _disconnect(remote_app):
# def disconnect(remote_app):
# def rest_disconnect(remote_app):
# 
# Path: invenio_oauthclient/_compat.py
# def monkey_patch_werkzeug():
#     """Patch top level removed modules."""
#     try:
#         from werkzeug import cached_property
#     except ImportError:
#         werkzeug.cached_property = werkzeug.utils.cached_property
#         werkzeug.parse_options_header = werkzeug.http.parse_options_header
#         werkzeug.url_quote = werkzeug.urls.url_quote
#         werkzeug.url_decode = werkzeug.urls.url_decode
#         werkzeug.url_encode = werkzeug.urls.url_encode


# Path: examples/orcid_app_rest.py
import os
from flask import Flask, redirect, url_for
from flask_babelex import Babel
from flask_login import current_user
from flask_menu import Menu as FlaskMenu
from invenio_accounts import InvenioAccounts
from invenio_accounts.views import blueprint as blueprint_user
from invenio_db import InvenioDB
from invenio_mail import InvenioMail as Mail
from invenio_userprofiles import InvenioUserProfiles
from invenio_userprofiles.views import \
    blueprint_api_init as blueprint_userprofile_api_init
from invenio_userprofiles.views import \
    blueprint_ui_init as blueprint_userprofile_ui_init
from invenio_oauthclient import InvenioOAuthClientREST
from invenio_oauthclient.contrib import orcid
from invenio_oauthclient.views.client import rest_blueprint as blueprint_client
from invenio_oauthclient._compat import monkey_patch_werkzeug  # noqa isort:skip
from flask_oauthlib.client import OAuth as FlaskOAuth  # noqa isort:skip


   .. code-block:: console

       $ ./app-teardown.sh

SPHINX-END

"""




monkey_patch_werkzeug()  # noqa isort:skip


# [ Configure application credentials ]
ORCID_APP_CREDENTIALS = dict(
    consumer_key=os.environ.get('ORCID_APP_CREDENTIALS_KEY'),
    consumer_secret=os.environ.get('ORCID_APP_CREDENTIALS_SECRET'),
)

# Create Flask application
app = Flask(__name__)

app.config.update(
    SQLALCHEMY_ECHO=False,
    SQLALCHEMY_DATABASE_URI=os.environ.get(
        'SQLALCHEMY_DATABASE_URI', 'sqlite:///orcid_app_rest.db'
    ),
    OAUTHCLIENT_REST_REMOTE_APPS=dict(

        orcid=orcid.REMOTE_SANDBOX_REST_APP,