Example #1
0
def refresh_token(device_type):
    if 'token' in session:
        '''認証済みの場合は有効性チェック'''
        my_api = sw.MyApi(
            sw.ApiClient(host=app.config.get('API_HOST'),
                         header_name='Authorization',
                         header_value='JWT %s' % session['token']))
        try:
            my_api.my_profile_get()
        except ApiException as err:
            '''有効でない場合はトークンを破棄'''
            if err.status == 401:
                session.pop('token')
            else:
                return render_template('plain.html', message='server error')
    '''セッションにトークンがない場合は匿名トークンを発行'''
    if 'token' not in session:
        auth_api = sw.AuthApi(sw.ApiClient(app.config.get('API_HOST')))
        auth = sw.Authenticate()
        auth.key = 'anonymous'
        auth.secret = 'anonymous'
        auth.device = device_type
        auth.trid = check_trid(cookies=request.cookies)
        result = auth_api.authenticate_post(authenticate=auth)
        session['token'] = result.access_token
    g.api = sw.ApiClient(host=app.config.get('API_HOST'),
                         header_name='Authorization',
                         header_value='JWT %s' % session['token'])
Example #2
0
def login() -> Response:
    """クラブレコチョクからの戻りURL"""
    if 'enable_id' in request.args:
        user_agent = request.headers.get('User-Agent')
        current_app.logger.info('User-Agent: %s' % user_agent)
        auth = sw.Authenticate()
        auth.key = 'session_key'
        auth.secret = request.args['enable_id']
        auth.device = check_device(request.user_agent)
        auth.trid = check_trid(cookies=request.cookies)
        auth_api = sw.AuthApi(g.api)
        try:
            token = auth_api.authenticate_post(authenticate=auth)
            login_user_(access_token=token.access_token)
            if 'next' in request.args and 'logout' not in request.args['next']:
                if 'regist' in request.args:
                    return redirect_(request.args['next'] + '?regist=complete')
                return redirect_(request.args['next'])
            if 'regist' in request.args:
                return redirect_(url_for('front.home') + '?regist=complete')
            return redirect_(url_for('front.home'))
        except ApiException as ex:
            current_app.logger.warning('login error: %s', ex)
            flash('認証に失敗しました', category='error')
        return redirect_(url_for('front.home'))
    if current_user.is_authenticated:
        return redirect_(url_for('front.home'))
    """クラブレコチョクへ認証しに行く"""
    if request.referrer and request.referrer.startswith(
            current_app.config.get('WEB_HOST')):
        next_ = request.referrer.replace(current_app.config.get('WEB_HOST'),
                                         '')
        ok_url = urllib.parse.quote(
            current_app.config.get('WEB_HOST') + '/login?next=' + next_)
        ok_url_regist = urllib.parse.quote(
            current_app.config.get('WEB_HOST') +
            '/login?regist=complete?next=' + next_)
    else:
        ok_url = urllib.parse.quote(
            current_app.config.get('WEB_HOST') + '/login')
        ok_url_regist = urllib.parse.quote(
            current_app.config.get('WEB_HOST') + '/login?regist=complete')
    param = '?service=wizy&devices_type=WEB&ok_url='
    silent_url = urllib.parse.quote(
        current_app.config.get('CLUB_RECOCHOKU_SILENT_RETURN') + param +
        ok_url)
    silent_url_r = urllib.parse.quote(
        current_app.config.get('CLUB_RECOCHOKU_SILENT_RETURN') + param +
        ok_url_regist)
    session.clear()
    silent_params = param + silent_url + '&ok_url_regist=' + silent_url_r
    if 'signup' in request.args:
        response = redirect(
            current_app.config.get('CLUB_RECOCHOKU_SIGNUP') + silent_params)
    else:
        response = redirect(
            current_app.config.get('CLUB_RECOCHOKU_LOGIN') + silent_params)
    response.set_cookie('agree', value=str(datetime.now().timestamp()))
    return response
Example #3
0
 def login(self, username, password, token_validity_seconds):
     api_instance = swagger_client.AuthApi(self.api_client)
     try:
         result = api_instance.auth_login_post(username, password, validityseconds=token_validity_seconds)
         if isinstance(result, Error):
             raise RuntimeError(Error.message)
     except Exception as e:
         raise e
     self.auth_success = result
Example #4
0
def login():
    """クリエイターのログイン画面"""
    if current_user.is_authenticated:
        logout_user_()
        return redirect_(url_for('creator.login'))
    form = CreatorLoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            auth_api = sw.AuthApi(api_client=g.api)
            auth = sw.Authenticate()
            auth.key = form.email.data
            auth.secret = form.password.data
            auth.device = check_device(user_agent=request.user_agent)
            try:
                token = auth_api.authenticate_post(authenticate=auth)
                current_app.logger.info("success login!")
                login_user_(token.access_token)
                return redirect_(url_for('creator.home'))
            except ApiException as ex:
                current_app.logger.warning('creator login: %s', ex)
                flash('メールアドレスまたはパスワードが不正です', category='error')
        else:
            flash('メールアドレスまたはパスワードが不正です', category='error')
    return render_template('creator_login.html', form=form)
Example #5
0
 def build_auth_api_client(self):
     # create an instance of the API class
     return swagger_client.AuthApi(
         swagger_client.ApiClient(self.build_config()))
 def __init__(self, *args, **kwargs) -> None:
     super().__init__(*args, **kwargs)
     self.client = swagger_client.AuthApi(self.api_client)
Example #7
0
from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from swagger_client.models.auth_success import AuthSuccess
from pprint import pprint

# create an configuration for the general API client
api_client_config = swagger_client.Configuration()
api_client_config.host = "https://localhost:8443/v0"
api_client_config.verify_ssl = False  #Do not do this for production use, only required to make it work with self signed certificates

# create an instance of the general API client
api_client = swagger_client.ApiClient(api_client_config)

# create an instance of the API class
api_instance = swagger_client.AuthApi(api_client)

try:
    # DUMMY TEST CODE
    # Logs a user in and returns an JWT token for authentication
    username = "******"
    password = "******"
    validitySeconds = 7200
    result = api_instance.auth_login_post(
        username, password,
        validityseconds=validitySeconds)  # type: AuthSuccess
    pprint(result.token)
    pprint(result)
except ApiException as e:
    print("Exception when calling AuthApi->auth_login_post: %s\n" % e)