flask-oauth2-login icon indicating copy to clipboard operation
flask-oauth2-login copied to clipboard

Error when logging in

Open tomkcook opened this issue 9 years ago • 1 comments

When I try to use something fairly similar to the example, I get redirected to the Google login page and then, when I click allow, get this in my browser:

{
  "error": "(invalid_request) Invalid client_id parameter value."
}

The ha.settings module contains definitions for GOOGLE_LOGIN_REDIRECT_SCHEME, GOOGLE_LOGIN_CLIENT_ID, GOOGLE_LOGIN_CLIENT_SECRET, SERVER_NAME and SECRET_KEY, among others. I've checked that the value of GOOGLE_LOGIN_CLIENT_ID matches the value in the Google developer's console. What's going on?

Complete Flask code below, though the ha.settings and ha.ha_data modules are left as an exercise for the reader.

import ha.ha_data, ha.settings
import logging
from flask import Flask, redirect, render_template, session, jsonify
from flask.ext.login import LoginManager, current_user, login_user, logout_user, login_required

from flask_oauth2_login import GoogleLogin

application = Flask(__name__)
handler = logging.FileHandler('/tmp/flask.log')
handler.setLevel(logging.DEBUG)
application.logger.addHandler(logger)

application.config.from_object('ha.settings')

google = GoogleLogin(application)
lm = LoginManager()
lm.init_app(application)

@lm.user_loader
def load_user(id):
    return ha_data.User.query.get(int(id))

@lm.token_loader
def load_user_from_token(token):
    return ha_data.session.query().filter(User.accesstoken == token).first()

lm.login_view = 'login'

@application.route('/login')
def login():
    return redirect(google.authorization_url())

@application.route('/')
@login_required
def index():
    return render_template('index.html')

@google.login_success
def login_success(token, profile):
    return jsonify(token = token, profile = profile)

@google.login_failure
def login_failure(e):
    return jsonify(error = str(e))

if __name__ == '__main__':
    application.run()

tomkcook avatar Feb 11 '16 12:02 tomkcook

...and have checked that google.client_id is ending up with the right value.

tomkcook avatar Feb 11 '16 12:02 tomkcook