def create_module(app, **kwargs):
    from .models import User
    login_manager.init_app(app)
    bcrypt.init_app(app)
    openid.init_app(app)
    jwt.init_app(app)

    facebook_blueprint = make_facebook_blueprint(
        client_id=app.config.get("FACEBOOK_CLIENT_ID"),
        client_secret=app.config.get("FACEBOOK_CLIENT_SECRET"),
        scope=["email"])

    github_blueprint = make_github_blueprint(
        client_id=app.config.get("GITHUB_CLIENT_ID"),
        client_secret=app.config.get("GITHUB_CLIENT_SECRET"),
        scope=["user:email"])

    gitlab_blueprint = make_gitlab_blueprint(
        client_id=app.config.get("GITLAB_CLIENT_ID"),
        client_secret=app.config.get("GITLAB_CLIENT_SECRET"),
        scope=["read_user email"])
    from .routes import auth_blueprint
    app.register_blueprint(auth_blueprint)
    app.register_blueprint(facebook_blueprint, url_prefix="/auth/login")
    app.register_blueprint(github_blueprint, url_prefix="/auth/login")
    app.register_blueprint(gitlab_blueprint, url_prefix="/auth/login")

    event.listen(User, "after_insert", greeting_sender)
def test_blueprint_factory_default():
    # Test with gitlab.com
    glbp = make_gitlab_blueprint(
        client_id="foo", client_secret="bar", scope="read_user", redirect_to="index"
    )
    assert isinstance(glbp, OAuth2ConsumerBlueprint)
    assert glbp.session.scope == "read_user"
    assert glbp.session.base_url == "https://gitlab.com/api/v4/"
    assert glbp.session.client_id == "foo"
    assert glbp.client_secret == "bar"
    assert glbp.authorization_url == "https://gitlab.com/oauth/authorize"
    assert glbp.token_url == "https://gitlab.com/oauth/token"
Example #3
0
def test_load_from_config():
    app = Flask(__name__)
    app.secret_key = "anything"
    app.config["GITLAB_OAUTH_CLIENT_ID"] = "foo"
    app.config["GITLAB_OAUTH_CLIENT_SECRET"] = "bar"
    gitlab_bp = make_gitlab_blueprint(redirect_to="index")
    app.register_blueprint(gitlab_bp)

    resp = app.test_client().get("/gitlab")
    url = resp.headers["Location"]
    client_id = URLObject(url).query.dict.get("client_id")
    assert client_id == "foo"
Example #4
0
def test_context_local():
    responses.add(responses.GET, "https://google.com")

    # set up two apps with two different set of auth tokens
    app1 = Flask(__name__)
    glbp1 = make_gitlab_blueprint(
        "foo1",
        "bar1",
        redirect_to="url1",
        backend=MemoryBackend({"access_token": "app1"}),
    )
    app1.register_blueprint(glbp1)

    app2 = Flask(__name__)
    glbp2 = make_gitlab_blueprint(
        "foo2",
        "bar2",
        redirect_to="url2",
        backend=MemoryBackend({"access_token": "app2"}),
    )
    app2.register_blueprint(glbp2)

    # outside of a request context, referencing functions on the `gitlab` object
    # will raise an exception
    with pytest.raises(RuntimeError):
        gitlab.get("https://google.com")

    # inside of a request context, `gitlab` should be a proxy to the correct
    # blueprint session
    with app1.test_request_context("/"):
        app1.preprocess_request()
        gitlab.get("https://google.com")
        request = responses.calls[0].request
        assert request.headers["Authorization"] == "Bearer app1"

    with app2.test_request_context("/"):
        app2.preprocess_request()
        gitlab.get("https://google.com")
        request = responses.calls[1].request
        assert request.headers["Authorization"] == "Bearer app2"
Example #5
0
def test_blueprint_factory_default():
    # Test with gitlab.com
    glbp = make_gitlab_blueprint(client_id="foo",
                                 client_secret="bar",
                                 scope="read_user",
                                 redirect_to="index")
    assert isinstance(glbp, OAuth2ConsumerBlueprint)
    assert glbp.session.scope == "read_user"
    assert glbp.session.base_url == "https://gitlab.com/api/v4/"
    assert glbp.session.client_id == "foo"
    assert glbp.client_secret == "bar"
    assert glbp.authorization_url == "https://gitlab.com/oauth/authorize"
    assert glbp.token_url == "https://gitlab.com/oauth/token"
Example #6
0
def test_blueprint_factory_custom():
    glbp2 = make_gitlab_blueprint(client_id="foo",
                                  client_secret="bar",
                                  scope="read_user",
                                  redirect_to="index",
                                  hostname="git.example.com")
    assert isinstance(glbp2, OAuth2ConsumerBlueprint)
    assert glbp2.session.scope == "read_user"
    assert glbp2.session.base_url == "https://git.example.com/api/v4/"
    assert glbp2.session.client_id == "foo"
    assert glbp2.client_secret == "bar"
    assert glbp2.authorization_url == "https://git.example.com/oauth/authorize"
    assert glbp2.token_url == "https://git.example.com/oauth/token"
def test_blueprint_factory_custom():
    glbp = make_gitlab_blueprint(
        client_id="foo",
        client_secret="bar",
        scope="read_user",
        redirect_to="index",
        hostname="git.example.com",
    )
    assert isinstance(glbp, OAuth2ConsumerBlueprint)
    assert glbp.session.scope == "read_user"
    assert glbp.session.base_url == "https://git.example.com/api/v4/"
    assert glbp.session.client_id == "foo"
    assert glbp.client_secret == "bar"
    assert glbp.authorization_url == "https://git.example.com/oauth/authorize"
    assert glbp.token_url == "https://git.example.com/oauth/token"
Example #8
0
app.secret_key = os.environ.get("FLASK_SECRET")
discord_url = os.environ.get("WEBHOOK")
app.config["GITHUB_OAUTH_CLIENT_ID"] = os.environ.get(
    "REPOSI_GITHUB_CLIENT_ID")
app.config["GITHUB_OAUTH_CLIENT_SECRET"] = os.environ.get(
    "REPOSI_GITHUB_SECRET")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
# Github blueprint
github_bp = make_github_blueprint()
github_bp.redirect_url = "https://reposi.0cdn.me/docs"
app.register_blueprint(github_bp, url_prefix="/login")

app.config["GITLAB_OAUTH_CLIENT_ID"] = os.environ.get("REPOSI_GITLAB_ID")
app.config["GITLAB_OAUTH_CLIENT_SECRET"] = os.environ.get(
    "REPOSI_GITLAB_SECRET")
gitlab_bp = make_gitlab_blueprint()
app.register_blueprint(gitlab_bp, url_prefix="/login")

app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True

# Database model & connection
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite"
db = SQLAlchemy(app)
git_token = os.environ.get("GITHUB_TOKEN")
print(git_token)


@oauth_authorized.connect
def redirect_to_docs(blueprint, token):
    blueprint.token = token
    user = []
Example #9
0
 def _make_app(*args, **kwargs):
     app = Flask(__name__)
     app.secret_key = "whatever"
     blueprint = make_gitlab_blueprint(*args, **kwargs)
     app.register_blueprint(blueprint)
     return app
Example #10
0
 def _make_app(*args, **kwargs):
     app = Flask(__name__)
     app.secret_key = "whatever"
     blueprint = make_gitlab_blueprint(*args, **kwargs)
     app.register_blueprint(blueprint)
     return app