Ejemplo n.º 1
0
def _configure_provider(app, blueprint, oauth, config):
    """
    Configures and registers a service provider connection Factory with the 
    main application. The connection factory is accessible via:
    
        from flask import current_app as app
        app.social.<provider_id>
    """
    provider_id = config['id']
    o_config = config['oauth']

    try:
        o_config['consumer_key']
        o_config['consumer_secret']
    except KeyError:
        raise Exception('consumer_key and/or consumer_secret not found '
                        'for provider %s' % config['display_name'])

    service_provider = oauth.remote_app(provider_id, **o_config)

    def get_handler(clazz_name, config):
        return get_class_by_name(clazz_name)(**config)

    connect_handler = get_handler(config['connect_handler'], o_config)
    login_handler = get_handler(config['login_handler'], o_config)

    Factory = get_class_by_name(config['connection_factory'])

    setattr(service_provider, 'get_connection', Factory(**o_config))
    setattr(app.social, provider_id, service_provider)

    @service_provider.tokengetter
    def get_token():
        # Social doesn't use the builtin remote method calls feature of the
        # Flask-OAuth extension so we don't need to return a token. This does,
        # however, need to be configured
        return None

    @blueprint.route('/connect/%s' % provider_id,
                     methods=['GET'],
                     endpoint='connect_%s_callback' % provider_id)
    @login_required
    @service_provider.authorized_handler
    def connect_callback(response):
        """The route which the provider should redirect to after a user
        attempts to connect their account with the provider with their local
        application account
        """
        return connect_handler(response)

    @blueprint.route('/login/%s' % provider_id,
                     methods=['GET'],
                     endpoint='login_%s_callback' % provider_id)
    @service_provider.authorized_handler
    def login_callback(response):
        """The route which the provider should redirect to after a user
        attempts to login with their account with the provider
        """
        return login_handler(response)
Ejemplo n.º 2
0
def _configure_provider(app, blueprint, oauth, config):
    """
    Configures and registers a service provider connection Factory with the 
    main application. The connection factory is accessible via:
    
        from flask import current_app as app
        app.social.<provider_id>
    """
    provider_id = config["id"]
    o_config = config["oauth"]

    try:
        o_config["consumer_key"]
        o_config["consumer_secret"]
    except KeyError:
        raise Exception("consumer_key and/or consumer_secret not found " "for provider %s" % config["display_name"])

    service_provider = oauth.remote_app(provider_id, **o_config)

    def get_handler(clazz_name, config):
        return get_class_by_name(clazz_name)(**config)

    connect_handler = get_handler(config["connect_handler"], o_config)
    login_handler = get_handler(config["login_handler"], o_config)

    Factory = get_class_by_name(config["connection_factory"])

    setattr(service_provider, "get_connection", Factory(**o_config))
    setattr(app.social, provider_id, service_provider)

    @service_provider.tokengetter
    def get_token():
        # Social doesn't use the builtin remote method calls feature of the
        # Flask-OAuth extension so we don't need to return a token. This does,
        # however, need to be configured
        return None

    @blueprint.route("/connect/%s" % provider_id, methods=["GET"], endpoint="connect_%s_callback" % provider_id)
    @login_required
    @service_provider.authorized_handler
    def connect_callback(response):
        """The route which the provider should redirect to after a user
        attempts to connect their account with the provider with their local
        application account
        """
        return connect_handler(response)

    @blueprint.route("/login/%s" % provider_id, methods=["GET"], endpoint="login_%s_callback" % provider_id)
    @service_provider.authorized_handler
    def login_callback(response):
        """The route which the provider should redirect to after a user
        attempts to login with their account with the provider
        """
        return login_handler(response)
Ejemplo n.º 3
0
 def get_handler(clazz_name, config):
     return get_class_by_name(clazz_name)(**config)
Ejemplo n.º 4
0
 def get_handler(clazz_name, config):
     return get_class_by_name(clazz_name)(**config)