|
dolibarr 25.0.0-alpha
|

Public Member Functions | |
| __construct ($db) | |
| Constructor. | |
| getCredential ($server=null, $get=null) | |
| Extract the credential presented by the caller. | |
| authenticate ($server=null, $get=null) | |
| Authenticate the caller. | |
| getWwwAuthenticateHeader ($resourcemetadataurl='') | |
| Value of the WWW-Authenticate header to send with a 401. | |
Public Attributes | |
| const | MODE_USER = 'user' |
| Credential mode: an individual user API key was presented. | |
| const | MODE_SHARED = 'shared' |
| Credential mode: the shared AI_MCP_API_KEY was presented. | |
Private Member Functions | |
| fetchUserIdFromApiKey ($credential) | |
| Look up the active user owning this API key. | |
McpAuth Class.
Resolves the credential presented by an MCP client and turns it into a Dolibarr identity. Two credentials are accepted:
The class deliberately holds no state beyond the result of the last call and touches neither the HTTP response nor the session: it reads a request and answers a question. That is what lets the MCP entry point stay a thin script today, and lets the same logic be handed to an AuthorizationMiddleware later without being rewritten.
Definition at line 45 of file mcpauth.class.php.
| McpAuth::__construct | ( | $db | ) |
| McpAuth::authenticate | ( | $server = null, | |
| $get = null ) |
Authenticate the caller.
On success, $this->userid holds the user to run the request as (0 when the shared key was used) and $this->mode says which credential matched. On failure, $this->error and $this->httpcode hold what to answer.
| array<string,mixed>|null | $server Server variables, defaults to $_SERVER |
| array<string,mixed>|null | $get Query parameters, defaults to $_GET |
Definition at line 185 of file mcpauth.class.php.
References dol_syslog(), fetchUserIdFromApiKey(), getCredential(), getDolGlobalString(), MODE_SHARED, MODE_USER, and user.
|
private |
Look up the active user owning this API key.
The lookup matches the REST API: the key is stored either plain or encrypted, and moves to the token table when API_IN_TOKEN_TABLE is set. Entity selection is not handled here; MCP requests run in the entity of the endpoint, and multicompany switching is a separate piece of work.
| string | $credential | Credential presented by the caller |
Definition at line 287 of file mcpauth.class.php.
References dol_syslog(), dolDecrypt(), dolEncrypt(), and getDolGlobalString().
Referenced by authenticate().
| McpAuth::getCredential | ( | $server = null, | |
| $get = null ) |
Extract the credential presented by the caller.
Accepted forms, in order of precedence, mirroring the REST API (see Api Access class) so a key that works on /api/index.php works here:
The Authorization header is read from several places on purpose: Apache in CGI/FastCGI mode does not expose it unless CGIPassAuth is on, and the usual workaround republishes it as REDIRECT_HTTP_AUTHORIZATION. Reading $_SERVER alone makes Bearer authentication fail on those setups with no diagnostic other than a 401.
| array<string,mixed>|null | $server Server variables, defaults to $_SERVER |
| array<string,mixed>|null | $get Query parameters, defaults to $_GET |
Definition at line 121 of file mcpauth.class.php.
References dol_string_nounprintableascii().
Referenced by authenticate().
| McpAuth::getWwwAuthenticateHeader | ( | $resourcemetadataurl = '' | ) |
Value of the WWW-Authenticate header to send with a 401.
RFC 6750 section 3 requires the challenge on a rejected Bearer request; without it a client cannot tell "this endpoint wants a token" from "this endpoint is broken". When an authorization server is added, the URL of the Protected Resource Metadata document is passed here and clients discover it as described by RFC 9728 section 5.1.
| string | $resourcemetadataurl | Absolute URL of the Protected Resource Metadata document, if any |
Definition at line 266 of file mcpauth.class.php.