Skip to content

How to use google OAuth in caravel #755

Closed

Description

@thomastanmin93

Hi guys,

I have a question about how to use google OAuth in caravel, I check the docs from http://flask-appbuilder.readthedocs.io/en/latest/security.html#authentication-oauth, and add the following codes in config.py file:

AUTH_TYPE = AUTH_OAUTH

OAUTH_PROVIDERS = [
    {'name':'twitter', 'icon':'fa-twitter',
        'remote_app': {
            'consumer_key':'TWITTER KEY',
            'consumer_secret':'TWITTER SECRET',
            'base_url':'https://api.twitter.com/1.1/',
            'request_token_url':'https://api.twitter.com/oauth/request_token',
            'access_token_url':'https://api.twitter.com/oauth/access_token',
            'authorize_url':'https://api.twitter.com/oauth/authenticate'}
    },
    {'name':'google', 'icon':'fa-google', 'token_key':'access_token',
        'remote_app': {
            'consumer_key':'GOOGLE KEY',
            'consumer_secret':'GOOGLE SECRET',
            'base_url':'https://www.googleapis.com/plus/v1/',
            'request_token_params':{
              'scope': 'https://www.googleapis.com/auth/userinfo.email'
            },
            'request_token_url':None,
            'access_token_url':'https://accounts.google.com/o/oauth2/token',
            'authorize_url':'https://accounts.google.com/o/oauth2/auth'}
    }
]

But I don't know where I should write the code like following according to the docs:

@appbuilder.sm.oauth_user_info_getter
def my_user_info_getter(sm, provider, response=None):
    if provider == 'github':
        me = sm.oauth_remotes[provider].get('user')
        return {'username': me.data.get('login')}
    else:
        return {}

Anyone help me?

Activity

  1. mistercrunch commented on Jul 22, 2016

    @mistercrunch
    Member

    You should ask in the flask-appbuilder GH epo

  2. dugjason commented on Oct 14, 2016

    @dugjason

    @Thomasmisfit you ever have any luck getting Google OAuth to work with Caravel?

  3. iaperez commented on Nov 24, 2016

    @iaperez
    Contributor

    I'm integrating superset with a different oauth provider, and, while I have it working, it is an (awful) hack.

    Here are some tips:
    1.- Install Flask-OAuthlib (pip), last version, 0.9.3
    2.- The decorated function (my_user_info_getter) is not longer receiving the sm object, but the providers list (sm.oauth_remotes). You can check the declaration of the decorator in flask_appbuilder/security/manager.py
    3.- The decorated function needs access to the superset appbuilder object (defined in superset/_init.py).
    4.- I'm also using the decorated function to check the info of the user that is already stored on the superset user datamodel, and the superset roles, and for that, I need access to the sm object. I'm totally breaking responsibilities here :(...

    I think that a good example of accessing sm and appbuilder is superset/views.py... so I guess that one solution is to create a superset/my_own_security.py and put a reference on superset/ for that new library. It should be relatively easy to get new superset features working in your fork in the future.

  4. fenlon commented on Dec 6, 2016

    @fenlon

    @iaperez have you solve the problem? i want to integrating superset with our company oauth provider. can you give me your demo? thanks. my email: [email protected]

  5. Aung-Myint-Thein commented on Aug 9, 2017

    @Aung-Myint-Thein
  6. rageshpillai commented on Jul 8, 2018

    @rageshpillai

    @iaperez: i have same requirement. can you help me to implement the requirement.
    or provide an example of "superset with a different oauth provider"
    mailid :[email protected]

  7. karimzrh commented on Aug 11, 2019

    @karimzrh

    @Aung-Myint-Thein did you get this one? #7739
    Could you help resolve?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions