python-oauth-jaccount
Installation
pip install oauth-jaccount
Or add oauth-jaccount
into requirements.txt
.
Usage (Example)
from oauth_jaccount import JaccountClient
client = JaccountClient(client_id="client_id", client_secret="client_secret")
from flask import redirect, session
from your_great_project import app
REDIRECT_URL = "https://example.com/jaccount/auth"
@app.get("/jaccount/login")
def jaccount_login():
url, state = client.get_authorize_url(REDIRECT_URL)
session['jaccount_state'] = state
return redirect(url)
@app.get("/jaccount/auth")
def jaccount_auth(state: str, code: str):
if state != session.get('jaccount_state', ''):
return redirect("url after login error")
access_token, refresh_token, id_token = client.get_token(code, REDIRECT_URL)
result = client.call_rest_api(access_token, JaccountClient.API.PROFILE)
return redirect("url after login")
@app.get("/jaccount/logout")
def jaccount_logout():
redirect_url = "url after logout"
url = client.get_logout_url(redirect_url)
return redirect(url)
Advance Usage
get_token
and call_rest_api
have more flexible version: get_token_url
and get_rest_api_url
. You can use them to get the corresponding urls if you want to call them by yourselves (e.g., use aiohttp
to make async requests).
You may check the source code for details.
License
MIT