HEX
Server: Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/7.4.30
System: Windows NT website-api 10.0 build 20348 (Windows Server 2016) AMD64
User: SYSTEM (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: C:/github_repos/ho-xsj-website/auth/token.py
import json
from rauth import OAuth2Service

from . import user


def get_oauth_token(code, state):
    service = OAuth2Service(
        name="Casdoor",
        client_id=user.authConfig.client_id,
        client_secret=user.authConfig.client_secret,
        authorize_url="%s/api/login/oauth/authorize" % user.authConfig.endpoint,
        access_token_url="%s/api/login/oauth/access_token" % user.authConfig.endpoint,
        base_url="%s/" % user.authConfig.endpoint,
    )

    data = {
        'code': code,
        'grant_type': 'authorization_code',
    }

    session = service.get_auth_session(data=data, decoder=json.loads)
    res = session.access_token
    return res