Log In With APOC
half-nothing/flarum-ext-oauth-apoc
APOC OAuth provider for Flarum
- Downloads
- 0
- Version control
- github.com/FSD-Universe/flarum-ext-oauth-apoc
Flarum APOC OAuth Extension
A Flarum extension that adds APOC OAuth authentication support.
Installation
Use composer to install this extension:
composer require half-nothing/flarum-ext-oauth-apoc
Configuration
After installation:
- Enable extension in Flarum Admin panel
- Navigate to Extensions > Log In With APOC
- Configure the following settings:
- Client ID: Your APOC OAuth application client ID
- Client Secret: Your APOC OAuth application client secret
- Authorization URL: The OAuth2 authorization endpoint URL (e.g.,
https://api.apocfly.com/api/oauth/authorize) - Token URL: The OAuth2 token endpoint URL (e.g.,
https://api.apocfly.com/api/oauth/token) - User Info URL: The API endpoint to retrieve user information (e.g.,
https://api.apocfly.com/api/users/profiles/self)
- Save your settings
Important: This extension uses PKCE (Proof Key for Code Exchange) with the S256 method for enhanced security. PKCE is automatically enabled and required for all OAuth authentication flows.
API Response Format
The APOC OAuth provider returns user information in the following format when accessed via OAuth token:
User Info Endpoint Response (OAuth Token Access)
{
"code": "GET_CURRENT_PROFILE_SUCCESS",
"message": "获取当前用户信息成功",
"data": {
"username": "Half_nothing",
"email": "[email protected]",
"cid": 2352,
"avatar_url": "https://q2.qlogo.cn/headimg_dl?dst_uin=1483073537&spec=100",
"qq": 1483073537,
"register_time": "2024-01-01T00:00:00Z"
}
}
The extension extracts the following fields from the data object:
email(required): User's email addressusername: User's username (for suggestion)cid: User's numeric ID (fallback for username)avatar_url: User's avatar URL
Note: When accessing user information via OAuth token, only the following fields are returned: username, email, cid, qq, avatar_url, and register_time.
OAuth Endpoints
1. Authorization Request
- Endpoint:
GET /api/oauth/authorize - Parameters:
client_id: Your OAuth client IDredirect_uri: The callback URLresponse_type: Must becodescope: Currently onlyprofileis supportedstate(optional): State parameter for CSRF protectioncode_challenge(required): PKCE challenge using S256 methodcode_challenge_method(required): Must beS256
Note: PKCE is required by the APOC OAuth server. The extension automatically generates and includes the code_challenge and code_verifier parameters using the S256 method.
2. Access Token Request
- Endpoint:
POST /api/oauth/token - Content-Type:
application/json - Request Body:
{
"grant_type": "authorization_code",
"code": "authorization_code_from_previous_step",
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"code_verifier": "pkce_code_verifier"
}
Note: The code_verifier parameter is required for PKCE. The extension automatically generates the code_verifier and code_challenge pair and includes them in the OAuth flow.
- Response:
{
"access_token": "your_access_token",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "your_refresh_token",
"scope": "profile"
}
3. User Info Request
- Endpoint:
GET /users/profiles/self - Headers:
Authorization:Bearer {access_token}
PKCE Security
This extension implements PKCE (Proof Key for Code Exchange) using the S256 (SHA-256) method for enhanced security. PKCE provides protection against authorization code interception attacks, which is especially important for public clients.
How PKCE works:
- The client generates a cryptographically random
code_verifier - The client creates a
code_challengeby hashing thecode_verifierwith SHA-256 and encoding it in base64url - The client includes the
code_challengein the authorization request - The client sends the
code_verifierin the token exchange request - The server verifies that the
code_challengematches the hash of thecode_verifier
All PKCE parameters are automatically generated and managed by the extension - no manual configuration is required.
Links
License
This extension is licensed under MIT.
Versions
-
Version v0.1.4.
Likely works with Flarum v1.8.12.
-
4 additional versions.
-
Extension created.