概要
Authlib用OAuth 2サーバーのサンプル。
開発ツールできること
- Authorization code grant, with PKCE (RFC 7636). Public clients must use PKCE.
- Implicit grant.
- Resource owner password credentials grant.
- Client credentials grant.
計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- -2
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルExample of OAuth 2.0 server
An example of OAuth 2.0 authorization server built with Authlib and Flask. Read its code to learn how to build a server.
This page explains how to run the example. It assumes basic knowledge of OAuth 2.0. The Authlib documentation explains how to build a server. For a ready-to-use server to test an OAuth 2.0 client, see Auth Server Playground.
Features
The server supports these grants and endpoints:
- Authorization code grant, with PKCE (RFC 7636). Public clients must use PKCE.
- Implicit grant.
- Resource owner password credentials grant.
- Client credentials grant.
- Refresh token grant.
- Token revocation (RFC 7009).
- A protected resource,
/api/me, that needs theprofilescope.
Run the server
Run the server with uv:
uv run flask --app website run
The server listens on http://127.0.0.1:5000.
It stores its data in a SQLite database in the Flask instance folder.
Try the password grant
Open http://127.0.0.1:5000/ and log in with any user name.
The server creates the user at the first login.
The password of every user is valid.
Then create a client:
- Click Create Client.
- Set Allowed Scope to
profile. - Set Allowed Grant Types to
password. - Keep
client_secret_basicas the token endpoint authentication method. - Submit the form. The home page shows the
client_idandclient_secretof the new client.
Request a token with the password grant:
curl -u ${client_id}:${client_secret} -X POST http://127.0.0.1:5000/oauth/token \
-d grant_type=password -d username=${username} -d password=valid -d scope=profile
The server returns a token:
{"access_token": "UGnmW1AnVJPWu9mLCbZwiWHHgW28An7Qq2uzBo5uQz", "expires_in": 864000, "refresh_token": "Z0kS5WFkCGUOGZZEoK9fFUXIxXGI4HiOKJzZ336KJlUKc4Hy", "scope": "profile", "token_type": "Bearer"}
Call the protected resource with the access token:
curl -H "Authorization: Bearer ${access_token}" http://127.0.0.1:5000/api/me
{"id":1,"username":"alice"}
The other endpoints are /oauth/authorize and /oauth/revoke.
Grant types and redirect URIs go one per line in the client form.
Development
Run the tests:
uv run pytest
Install the Git hooks that check the code style and the commit messages:
uv run prek install
License
The server is distributed under the BSD 3-Clause license. See LICENSE.
関連プロジェクトを探す
読み込み中…