This is a mock implementation of an OpenID Connect (OIDC) server using Flask. It supports client_credentials
, authorization_code
, and refresh_token
grant types. The server also provides endpoints for OpenID configuration and JSON Web Key Set (JWKS).
- Authorization Endpoint: Handles authorization requests and issues authorization codes.
- Token Endpoint: Issues access tokens and refresh tokens based on authorization codes, client credentials, and refresh tokens.
- UserInfo Endpoint: Provides user information based on access tokens.
- OAuth 2.0 Dynamic Client Registration: Full support for RFC 7591 and RFC 7592
- Client registration endpoint
- Client configuration management (read, update, delete)
- Support for both web and native applications
- Public and confidential client types
- JWKS Endpoint: Provides the JSON Web Key Set for token verification.
- Supports Multiple Grant Types: Supports
client_credentials
,authorization_code
, andrefresh_token
grant types. - Supports PKCE: Supports Proof Key for Code Exchange (PKCE) for authorization code flow.
- Well-Known Configuration: Provides the OpenID configuration for the server.
- Authorization Endpoint:
/authorize
- Token Endpoint:
/token
- UserInfo Endpoint:
/userinfo
- Client Registration Endpoint:
/register
(POST) - Client Configuration Endpoint:
/register/{client_id}
(GET, PUT, DELETE) - Well-Known Configuration:
/.well-known/openid-configuration
- JWKS Endpoint:
/jwks
- Python 3.7+
- Flask
- Flask-SQLAlchemy
- cryptography
- PyJWT
-
Clone the repository:
git clone https://github.com/prd1137/mock-oidc.git cd mock-oidc
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
python3 run.py
-
The server will start at
http://localhost:5000
.
Send a GET request to the authorization endpoint:
GET /authorize?response_type=code&client_id=your-client-id&redirect_uri=your-redirect-uri&state=random-state-string
Send a GET request to the authorization endpoint with PKCE parameters:
GET /authorize?response_type=code&client_id=your-client-id&redirect_uri=your-redirect-uri&state=random-state-string&code_challenge=code-challenge&code_challenge_method=S256
Send a POST request to the token endpoint to exchange an authorization code for tokens:
POST /token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&client_id=your-client-id&client_secret=your-client-secret&code=authorization-code
Send a POST request to the token endpoint with PKCE parameters:
POST /token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&client_id=your-client-id&client_secret=your-client-secret&code=authorization-code&code_verifier=code-verifier&redirect_uri=your-redirect-uri
Send a GET request to the userinfo endpoint with the access token:
GET /userinfo
Authorization: Bearer access-token
Send a POST request to the register endpoint to register a new client:
POST /register
Content-Type: application/json
{
"redirect_uris": "http://localhost:5000/callback"
}
Retrieve the OpenID configuration:
GET /.well-known/openid-configuration
Retrieve the JSON Web Key Set:
GET /jwks
Send a POST request to the token endpoint to refresh an access token:
POST /token
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&client_id=your-client-id&client_secret=your-client-secret&refresh_token=refresh-token
This server implements RFC 7591 (OAuth 2.0 Dynamic Client Registration Protocol) and RFC 7592 (OAuth 2.0 Dynamic Client Registration Management Protocol).
-
Register a new client:
curl -X POST http://localhost:5000/register \ -H "Content-Type: application/json" \ -d '{ "redirect_uris": ["https://example.com/callback"], "client_name": "My App", "application_type": "web" }'
-
Use the returned
client_id
andclient_secret
for OAuth flows -
Manage your client using the
registration_access_token
:# Read client configuration curl -X GET http://localhost:5000/register/{client_id} \ -H "Authorization: Bearer {registration_access_token}" # Update client configuration curl -X PUT http://localhost:5000/register/{client_id} \ -H "Authorization: Bearer {registration_access_token}" \ -H "Content-Type: application/json" \ -d '{"client_name": "Updated App Name"}' # Delete client curl -X DELETE http://localhost:5000/register/{client_id} \ -H "Authorization: Bearer {registration_access_token}"
For detailed examples and documentation, see DYNAMIC_CLIENT_REGISTRATION.md.