<commit_before>=================
Flask-GoogleLogin
=================
.. currentmodule:: flask_googlelogin

Flask-GoogleLogin extends Flask-Login to use Google OAuth2's authorization.

.. contents::
   :local:
   :backlinks: none

Usage
=====
Get started by creating a `GoogleLogin` instance::

    from flask_googlelogin import GoogleLogin
    googlelogin = GoogleLogin(app)
    # or
    googlelogin = GoogleLogin()
    googlelogin.init_app(app)

A `flaskext.login.LoginManager` instance is implicitly created in
`GoogleLogin.init_app` but you can also pass your own::

    from flask_login import LoginManager
    login_manager = LoginManager()
    login_manager.init_app(app)
    googlelogin = GoogleLogin(app, login_manager)

.. tip::
    `flask_googlelogin` recursively imports from `flaskext.login` so you can do
    something like this::

        from flask_googlelogin import LoginManager

Next, you need to specify an OAuth2 callback route::

    @app.route('/oauth2callback')
    @googlelogin.oauth2callback
    def create_or_update_user(userinfo=None, credentials=None, **params):
        if userinfo and credentials:
            user = User.filter_by(google_id=userinfo['id']).first()
            if user:
                user.name = userinfo['name']
                user.avatar = userinfo['picture']
            else:
                user = User(google_id=userinfo['id'],
                            name=userinfo['name'],
                            avatar=userinfo['picture'])
            db.session.add(user)
            db.session.flush()
            login_user(user)
            return redirect(url_for('index'))
        else:
            return googlelogin.login_manager.unauthorized()

Decorate views with `flaskext.login.login_required` and you're done! ::

    @app.route('/profile')
    @login_required
    def profile():
        return render_template('profile.html')

Get the Google auth URL using `GoogleLogin.login_url`. You can also include
extra params to `login_url` and they'll be passed to your
`GoogleLogin.oauth2callback`::

    googlelogin.login_url(section='notifications', next=url_for('.profile'))

You can also configure Google auth url params::

    googlelogin.login_url(approval_prompt='force', access_type='offline')
    googlelogin.login_url(redirect_uri=url_for('admin'))

Configuration
=============

Google API
------------------

============================ ===================================================
`GOOGLE_LOGIN_CLIENT_ID`     Client ID (create one at
                             https://code.google.com/apis/console)
`GOOGLE_LOGIN_CLIENT_SECRET` Client Secret
`GOOGLE_LOGIN_CLIENT_SCOPES` Default scopes
`GOOGLE_LOGIN_REDIRECT_URI`  Default redirect URI<commit_msg>More docs fix<commit_after>=================
Flask-GoogleLogin
=================
.. currentmodule:: flask_googlelogin

Flask-GoogleLogin extends Flask-Login to use Google OAuth2's authorization.

.. contents::
   :local:
   :backlinks: none

Usage
=====
Get started by creating a `GoogleLogin` instance::

    from flask_googlelogin import GoogleLogin
    googlelogin = GoogleLogin(app)
    # or
    googlelogin = GoogleLogin()
    googlelogin.init_app(app)

A `flaskext.login.LoginManager` instance is implicitly created in
`GoogleLogin.init_app` but you can also pass your own::

    from flask_login import LoginManager
    login_manager = LoginManager()
    login_manager.init_app(app)
    googlelogin = GoogleLogin(app, login_manager)

.. tip::
    `flask_googlelogin` recursively imports from `flaskext.login` so you can do
    something like this::

        from flask_googlelogin import LoginManager

Next, you need to specify an OAuth2 callback route::

    @app.route('/oauth2callback')
    @googlelogin.oauth2callback
    def create_or_update_user(token, userinfo, **params):
        user = User.filter_by(google_id=userinfo['id']).first()
        if user:
            user.name = userinfo['name']
            user.avatar = userinfo['picture']
        else:
            user = User(google_id=userinfo['id'],
                        name=userinfo['name'],
                        avatar=userinfo['picture'])
        db.session.add(user)
        db.session.flush()
        login_user(user)
        return redirect(url_for('index'))

Decorate views with `flaskext.login.login_required` and you're done! ::

    @app.route('/profile')
    @login_required
    def profile():
        return render_template('profile.html')

Get the Google auth URL using `GoogleLogin.login_url`. You can also include
extra params to `login_url` and they'll be passed to your
`GoogleLogin.oauth2callback`::

    googlelogin.login_url(section='notifications', next=url_for('.profile'))

You can also configure Google auth url params::

    googlelogin.login_url(approval_prompt='force', access_type='offline')
    googlelogin.login_url(redirect_uri=url_for('admin'))

Configuration
=============

Google API
------------------

============================ ===================================================
`GOOGLE_LOGIN_CLIENT_ID`     Client ID (create one at
                             https://code.google.com/apis/console)
`GOOGLE_LOGIN_CLIENT_SECRET` Client Secret
`GOOGLE_LOGIN_CLIENT_SCOPES` Default scopes
`GOOGLE_LOGIN_REDIRECT_URI`  Default redirect URI
{'fraction_non_alphanumeric': 0.14548209888236407, 'fraction_numerical': 0.0018942981625307824, 'mean_word_length': 3.422110552763819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303406', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1461, 'n_words': 362}