Unverified Commit adcc7f15 authored by Peter Stanko's avatar Peter Stanko
Browse files

Fixing dependencies for the portal

parent c32cdd75
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ flask-jwt-extended = "*"
marshmallow-enum = "*"
storage = {editable = true,ref = "master",git = "https://gitlab.fi.muni.cz/grp-kontr2/kontr-storage-module.git"}
gitpython = "*"
flask-oauthlib = "*"
pyopenssl = "*"
gunicorn = "*"
flask-cors = "*"
@@ -29,6 +28,8 @@ coloredlogs = "*"
redis = "*"
python-dotenv = "*"
pyyaml = "*"
muni-is-api = {editable = true,git = "https://git@gitlab.fi.muni.cz/grp-kontr2/is-api.git"}
authlib = "*"

[dev-packages]
pylint = "*"
+270 −258

File changed.

Preview size limit exceeded, changes collapsed.

+1 −2
Original line number Diff line number Diff line
@@ -10,8 +10,7 @@ from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from flask_migrate import Migrate
from flask_oauthlib.client import OAuth
from flask_sqlalchemy import SQLAlchemy
from authlib.flask.client import OAuth
from storage import Storage

from portal import logger, rest
+20 −24
Original line number Diff line number Diff line
from typing import Union

from flask import Flask, Response, make_response, redirect, request, session
from flask_oauthlib.client import OAuth, OAuthRemoteApp
from flask_oauthlib.client import OAuthRemoteApp
from flask_restplus import Namespace

from portal import logger, oauth
@@ -29,47 +29,49 @@ def gitlab_enabled(app: Flask) -> bool:
           app.config.get('GITLAB_CLIENT_SECRET')


def create_gitlab_app(oauth_app: OAuth) -> Union[OAuthRemoteApp, None]:
    if not gitlab_enabled(oauth_app.app):
        return None
def register_gitlab_app() -> Union[OAuthRemoteApp, None]:
    if not gitlab_enabled(oauth.app):
        return

    base_url = oauth_app.app.config['GITLAB_URL']
    client_id = oauth_app.app.config['GITLAB_CLIENT_ID']
    client_secret = oauth_app.app.config['GITLAB_CLIENT_SECRET']
    base_url = oauth.app.config['GITLAB_URL']
    client_id = oauth.app.app.config['GITLAB_CLIENT_ID']
    client_secret = oauth.oauth_app.app.config['GITLAB_CLIENT_SECRET']
    api_base_url = base_url + '/api/v4/'

    return oauth_app.remote_app(
        'gitlab',
        base_url=base_url,
    params = dict(
        client_id=client_id,
        client_secret=client_secret,
        base_url=api_base_url,
        request_token_url=None,
        access_token_url=base_url + "/oauth/token",
        authorize_url=base_url + "/oauth/authorize",
        access_token_method='POST',
        consumer_key=client_id,
        consumer_secret=client_secret
    )

    oauth.register('gitlab', **params)

gitlab = create_gitlab_app(oauth_app=oauth)

register_gitlab_app()


@oauth_namespace.route('/login')
class OAuthLogin(CustomResource):
    def get(self):
        if not gitlab:
        if gitlab_enabled(oauth.app):
            return {'message': 'Gitlab OAuth is not enabled'}, 404

        callback = rest_api.url_for(OAuthLoginAuthorized, _external=True)

        log.debug(f"Callback set: {callback}")
        return gitlab.authorize(callback=callback)
        return oauth.gitlab.authorize_redirect(callback)


@oauth_namespace.route('/login/authorized')
class OAuthLoginAuthorized(CustomResource):
    def get(self):
        if not gitlab:
        if not gitlab_enabled(oauth.app):
            return {'message': 'Gitlab OAuth is not enabled'}, 404
        resp = gitlab.authorized_response()
        resp = oauth.gitlab.authorize_access_token()
        if resp is None:
            return 'Access denied: reason=%s error=%s' % (
                request.args['error'],
@@ -82,12 +84,6 @@ class OAuthLoginAuthorized(CustomResource):
        return login


@gitlab.tokengetter
def get_gitlab_oauth_token():
    token = session.get('gitlab_token')
    return token


def user_oauth_register(user_info):
    from portal.service.rest import RestService
    rest = RestService()
@@ -121,7 +117,7 @@ def extract_token(resp):


def login_to_gitlab_with_token(token):
    me = gitlab.get('/api/v4/user')
    me = oauth.gitlab.get('/api/v4/user')
    user_info = extract_user_info(me.data)
    login = user_login(user_info)
    login.set_cookie('gitlab_token', token)
+0 −0

Empty file added.