Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/server/docs/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5167,6 +5167,16 @@
{
"type" : "string"
}
},
{
"description" : "RFC 8707 resource indicator (optional, all grants): binds the issued access token's audience (introspection aud) to this absolute URI, overriding the default aud = client id. Malformed values are rejected with invalid_target.",
"in" : "query",
"name" : "resource",
"required" : false,
"schema" :
{
"type" : "string"
}
}
],
"responses" :
Expand Down
10 changes: 9 additions & 1 deletion apps/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,13 @@ components:
type: string
description: Required for the device_code grant (from
/oauth2/device_authorization).
resource:
type: string
description: 'RFC 8707 §2.1 resource indicator (optional, all grants):
an absolute URI (scheme required, no fragment, max 255 chars)
that the issued access token''s audience (introspection `aud`)
is bound to, overriding the default aud = client id. A malformed
indicator is rejected with invalid_target.'
required:
- grant_type
type: object
Expand Down Expand Up @@ -7809,7 +7816,8 @@ paths:
$ref: '#/components/schemas/OAuth2Error'
description: >-
invalid_request / invalid_grant / unsupported_grant_type /
invalid_scope; device grant also returns authorization_pending,
invalid_scope / invalid_target (malformed RFC 8707 resource
indicator); device grant also returns authorization_pending,
slow_down (plus non-standard interval field), expired_token, or
access_denied here.
'401':
Expand Down
3 changes: 3 additions & 0 deletions clients/go/generated/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions clients/python/src/fulla/generated/models/token_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class TokenRequest:
token_endpoint_auth_method=client_secret_post; FORBIDDEN for PUBLIC clients whose method is 'none' (F-017).
scope (str | Unset): Space-separated scopes (client_credentials grant only).
device_code (str | Unset): Required for the device_code grant (from /oauth2/device_authorization).
resource (str | Unset): RFC 8707 §2.1 resource indicator (optional, all grants): an absolute URI (scheme
required, no fragment, max 255 chars) that the issued access token's audience (introspection `aud`) is bound to,
overriding the default aud = client id. A malformed indicator is rejected with invalid_target.
"""

grant_type: TokenRequestGrantType
Expand All @@ -43,6 +46,7 @@ class TokenRequest:
client_secret: str | Unset = UNSET
scope: str | Unset = UNSET
device_code: str | Unset = UNSET
resource: str | Unset = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
Expand All @@ -64,6 +68,8 @@ def to_dict(self) -> dict[str, Any]:

device_code = self.device_code

resource = self.resource

field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
Expand All @@ -87,6 +93,8 @@ def to_dict(self) -> dict[str, Any]:
field_dict["scope"] = scope
if device_code is not UNSET:
field_dict["device_code"] = device_code
if resource is not UNSET:
field_dict["resource"] = resource

return field_dict

Expand All @@ -111,6 +119,8 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:

device_code = d.pop("device_code", UNSET)

resource = d.pop("resource", UNSET)

token_request = cls(
grant_type=grant_type,
code=code,
Expand All @@ -121,6 +131,7 @@ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
client_secret=client_secret,
scope=scope,
device_code=device_code,
resource=resource,
)

token_request.additional_properties = d
Expand Down
6 changes: 5 additions & 1 deletion clients/ts/src/generated/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,10 @@ export type TokenRequest = {
* Required for the device_code grant (from /oauth2/device_authorization).
*/
device_code?: string;
/**
* RFC 8707 §2.1 resource indicator (optional, all grants): an absolute URI (scheme required, no fragment, max 255 chars) that the issued access token's audience (introspection `aud`) is bound to, overriding the default aud = client id. A malformed indicator is rejected with invalid_target.
*/
resource?: string;
};

/**
Expand Down Expand Up @@ -6323,7 +6327,7 @@ export type PostOauth2TokenData = {

export type PostOauth2TokenErrors = {
/**
* invalid_request / invalid_grant / unsupported_grant_type / invalid_scope; device grant also returns authorization_pending, slow_down (plus non-standard interval field), expired_token, or access_denied here.
* invalid_request / invalid_grant / unsupported_grant_type / invalid_scope / invalid_target (malformed RFC 8707 resource indicator); device grant also returns authorization_pending, slow_down (plus non-standard interval field), expired_token, or access_denied here.
*/
400: OAuth2Error;
/**
Expand Down
1 change: 1 addition & 0 deletions docs/domains/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ OAuth2 protocol endpoints (OAuth2_Protocol_Endpoint) keep the RFC 6749 §5.2 err
| `unauthorized_client` | 400 | 客户端无权使用该授权类型 |
| `unsupported_grant_type` | 400 | 不支持的授权类型 |
| `invalid_scope` | 400 | 请求的 scope 无效 |
| `invalid_target` | 400 | 请求的 resource 目标无效 |
| `server_error` | 500 | 服务器内部错误 |
| `temporarily_unavailable` | 503 | 服务暂时不可用 |
| `access_denied` | 403 | 授权请求被拒绝(用户无权或拒绝授权) |
Expand Down
1 change: 1 addition & 0 deletions frontends/admin/src/services/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const en: Record<string, string> = {
unauthorized_client: 'The client is not allowed to use this grant type',
unsupported_grant_type: 'Unsupported grant type',
invalid_scope: 'The requested scope is invalid',
invalid_target: 'The requested resource target is invalid',
server_error: 'Internal server error',
temporarily_unavailable: 'The service is temporarily unavailable',
access_denied: 'The authorization request was denied',
Expand Down
1 change: 1 addition & 0 deletions frontends/admin/src/services/messages/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const zhCN: Record<string, string> = {
unauthorized_client: '客户端无权使用该授权类型',
unsupported_grant_type: '不支持的授权类型',
invalid_scope: '请求的 scope 无效',
invalid_target: '请求的 resource 目标无效',
server_error: '服务器内部错误',
temporarily_unavailable: '服务暂时不可用',
access_denied: '授权请求被拒绝',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const FULLA_PROTOCOL_CODES = [
'unauthorized_client',
'unsupported_grant_type',
'invalid_scope',
'invalid_target',
'server_error',
'temporarily_unavailable',
'access_denied',
Expand Down
1 change: 1 addition & 0 deletions frontends/user/src/services/messages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const en: Record<string, string> = {
unauthorized_client: 'The client is not allowed to use this grant type',
unsupported_grant_type: 'Unsupported grant type',
invalid_scope: 'The requested scope is invalid',
invalid_target: 'The requested resource target is invalid',
server_error: 'Internal server error',
temporarily_unavailable: 'The service is temporarily unavailable',
access_denied: 'The authorization request was denied',
Expand Down
1 change: 1 addition & 0 deletions frontends/user/src/services/messages/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const zhCN: Record<string, string> = {
unauthorized_client: '客户端无权使用该授权类型',
unsupported_grant_type: '不支持的授权类型',
invalid_scope: '请求的 scope 无效',
invalid_target: '请求的 resource 目标无效',
server_error: '服务器内部错误',
temporarily_unavailable: '服务暂时不可用',
access_denied: '授权请求被拒绝',
Expand Down
11 changes: 7 additions & 4 deletions libs/common/src/error/ErrorCatalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,18 @@ const std::array<RawEntry, 47> &rawEntries()
return kEntries;
}

// OAuth2 protocol error codes (RFC 6749 §5.2 base set + RFC 7009/8628 codes).
const std::array<OAuthCatalogEntry, 13> &rawOAuthEntries()
// OAuth2 protocol error codes (RFC 6749 §5.2 base set + RFC 7009/8628 codes
// + RFC 8707 §2.1 invalid_target for resource-indicator audience binding).
const std::array<OAuthCatalogEntry, 14> &rawOAuthEntries()
{
static const std::array<OAuthCatalogEntry, 13> kEntries = {{
static const std::array<OAuthCatalogEntry, 14> kEntries = {{
{"invalid_request", 400, "请求参数缺失或无效", ""},
{"invalid_client", 401, "客户端认证失败", ""},
{"invalid_grant", 400, "授权许可无效或已过期", ""},
{"unauthorized_client", 400, "客户端无权使用该授权类型", ""},
{"unsupported_grant_type", 400, "不支持的授权类型", ""},
{"invalid_scope", 400, "请求的 scope 无效", ""},
{"invalid_target", 400, "请求的 resource 目标无效", ""},
{"server_error", 500, "服务器内部错误", ""},
{"temporarily_unavailable", 503, "服务暂时不可用", ""},
{"access_denied", 403, "授权请求被拒绝(用户无权或拒绝授权)", ""},
Expand Down Expand Up @@ -617,13 +619,14 @@ void ErrorCatalog::validateInvariants()
++oauthCounts[o.error];
}

static constexpr std::array<std::string_view, 13> kRequiredOAuthCodes = {{
static constexpr std::array<std::string_view, 14> kRequiredOAuthCodes = {{
"invalid_request",
"invalid_client",
"invalid_grant",
"unauthorized_client",
"unsupported_grant_type",
"invalid_scope",
"invalid_target",
"server_error",
"temporarily_unavailable",
"access_denied",
Expand Down
11 changes: 8 additions & 3 deletions libs/drogon/include/fulla/drogon/plugin/OAuth2Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,30 @@ class OAuth2Plugin : public drogon::Plugin<OAuth2Plugin>
const std::string &clientSecret,
const std::string &redirectUri,
const std::string &codeVerifier, // P0-3: PKCE code verifier
std::function<void(const Json::Value &)> &&callback
std::function<void(const Json::Value &)> &&callback,
const std::string &resource = "" // RFC 8707 §2 audience override
);

void exchangeCodeForAuthenticatedClient(
const std::string &code,
const std::string &clientId,
const std::string &redirectUri,
const std::string &codeVerifier,
std::function<void(const Json::Value &)> &&callback
std::function<void(const Json::Value &)> &&callback,
const std::string &resource = "" // RFC 8707 §2 audience override
);

/**
* @brief Refresh Access Token (Async)
* Returns JSON with {access_token, refresh_token, expires_in} or {error}
* `resource` (RFC 8707 §2.1) rebinds the rotated token's audience when
* non-empty.
*/
void refreshAccessToken(
const std::string &refreshToken,
const std::string &clientId,
std::function<void(const Json::Value &)> &&callback
std::function<void(const Json::Value &)> &&callback,
const std::string &resource = ""
);

/**
Expand Down
6 changes: 6 additions & 0 deletions libs/drogon/include/fulla/drogon/validation/RuleSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class RuleSet
static std::optional<std::string> validateResponseType(const std::string &type);
static std::optional<std::string> validateGrantType(const std::string &type);
static std::optional<std::string> validateToken(const std::string &token);
/// RFC 8707 §2.1 resource indicator: must be an absolute URI (scheme
/// required), carry no fragment and no whitespace, and fit the
/// oauth2_access_tokens.audience column (255). Empty is valid ==
/// "no audience binding requested" (callers gate on emptiness first).
/// Returns an error message or nullopt.
static std::optional<std::string> validateResourceIndicator(const std::string &resource);

static std::vector<std::string> oauth2Authorize(const ::drogon::HttpRequestPtr &req);
static std::vector<std::string> oauth2Token(const ::drogon::HttpRequestPtr &req);
Expand Down
Loading
Loading