Download the PHP package atwx/silverstripe-gate-api without Composer

On this page you can find all versions of the php package atwx/silverstripe-gate-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package silverstripe-gate-api

Silverstripe Gate API

A JWT authenticated content API for the SilverGate modules.

It exists so a central system can read and write content on any managed site without each site needing its own credentials, its own API tokens, or its own integration code. The API is deliberately generic: it reflects over the ORM, so every DataObject a project defines is reachable without writing anything site specific.

Two roles, one package

The module adopts whichever role fits what it finds installed alongside it. Both can be active at once on an install that carries both siblings.

Installed alongside Role What it does
atwx/silverstripe-gate-client site Answers API calls. Registers /_silvergateapi and validates tokens with the client's TokenService.
atwx/silverstripe-gate-manager manager Makes API calls, and serves them over MCP. Signs a token per ManagedSite with that site's own private key and calls its endpoint.
neither none The module is inert.

Neither sibling is a hard dependency; the roles are switched on by Silverstripe's moduleexists config rule. That is deliberate — neither gate-client nor gate-manager has to change to gain the API. Both already provide everything needed: the client validates tokens, and the manager's CryptographyService::generateJwt() already accepts an arbitrary claim payload.

Installation

Install it on the managed sites you want reachable, and on the manager instance you want to reach them from. It is the same package either way.

On a managed site

The site needs the SilverGate public key configured, exactly as for gate-client. If gate-client is already set up, there is nothing more to do — both modules read the same key, and the API is live as soon as the module is installed.

or via .env, with escaped newlines:

Note that the environment variable wins over the YAML config.

Until a key is configured every request is rejected, so installing the module does not by itself open anything.

On the manager

Nothing to configure. ManagedSite gains a callApi() method and a Test API button in the CMS.

create() and update() add scope: write for you; everything else defaults to read.

MCP server

Where the manager role is active, the module also serves a Model Context Protocol endpoint at /_silvergatemcp. One server covers every managed site: the tools take a site argument instead of the server being installed per site, so a client sees one small tool set rather than one set per site.

Clients discover everything else themselves. Registration is dynamic (RFC 7591), so there is nothing to configure by hand:

Document Path
Protected resource metadata (RFC 9728) /.well-known/oauth-protected-resource
Authorization server metadata (RFC 8414) /.well-known/oauth-authorization-server

Tools

sites_list first — it returns only the sites the caller may reach, and whether each is writable. Everything else mirrors one action of the site API: site_classes, site_schema, site_query, site_get, site_create, site_update, site_delete, site_publish, site_unpublish.

site_upload_url is the exception: files are too large to pass through an MCP connection, so the tool returns a presigned request instead and the client sends the file itself, e.g.

The token is limited to the upload action and expires with gate-client's token_max_age_seconds, so request a fresh one per file.

The write tools are hidden from tools/list unless the connection was authorised for writing, so a read-only client is not tempted by them.

Authorisation

OAuth 2.1 with PKCE, public clients only. Two scopes:

Scope Grants
mcp Read
mcp:write Read, plus create, update, delete, publish

The user authenticates with the manager's own login and is shown a consent screen naming the client and spelling out whether write access was asked for. The resulting token names a member, and every call downstream acts as that member: the site sees sub set to their email, applies their canEdit(), and records them in LastEdited.

Codes are single use, valid for two minutes, and bound to a PKCE S256 challenge. Codes and tokens are stored only as hashes.

Refresh tokens rotate: using one revokes it and issues a fresh pair. Three things end a session, so a leaked token cannot grant access forever:

Setting Default Ends
OAuthToken.lifetime 1 hour the access token; the client refreshes
OAuthToken.refresh_idle_lifetime 14 days a refresh token nobody uses
OAuthToken.refresh_absolute_lifetime 30 days the whole chain, counted from the original sign-in

A rotation carries the chain's start forward, so refreshing often cannot push the absolute limit out.

Reuse detection. Because rotation revokes the old refresh token, a spent one turning up again means someone kept a copy. There is no way to tell the real client from an attacker at that point, so every token that client holds for that member is revoked and the user has to sign in again. The event is logged with the member and client involved.

Tokens are visible in the CMS with member, client, scope, when the session started and when it was last used, and can be revoked by deleting them.

Deciding who reaches which site

SitePolicy answers that. By default a member may reach any site they could log into with SilverGate, on the grounds that the API grants nothing the browser login would not. Installs with a finer grained model narrow it:

Requests

All actions live under /_silvergateapi/<action>. Read actions accept GET or POST, write actions require POST. Parameters go in a JSON body.

Action Writes Body
ping —
classes search
schema class
query class, filter, sort, limit, offset, stage
get class, id, stage
create ✓ class, fields
update ✓ class, id, fields
delete ✓ class, id
publish ✓ class, id
unpublish ✓ class, id
upload ✓ multipart: file, folder, filename, title, publish

class accepts a fully qualified name or an unambiguous short name. filter takes ORM search filters, e.g. {"Title:PartialMatch": "news"}.

Discovering a site

classes lists what is reachable; schema describes one class including field types, the valid values of any Enum, and every relation. Call schema before writing — it is what makes the API usable without knowing the project.

Writing relations

has_one is set through its ID field. has_many, many_many and belongs_many_many take an array of IDs and replace the whole relation.

Writing a field the class does not have is an error rather than a silent no-op, so a typo surfaces immediately.

Uploading files

upload takes a multipart/form-data POST with the file in file. It goes through Silverstripe's own Upload, so the site's allowed extensions, size limits and file name filter apply as in the CMS. folder defaults to FileService.default_folder (Uploads) and is created if missing; publish defaults to true. The response is the File record, including AbsoluteURL.

The PHP limits upload_max_filesize and post_max_size still apply on the site.

Versioned records

Writes always go to the draft stage, whatever reading stage the request is in, and publish is a separate call. Reads default to draft; pass "stage": "live" for the published version.

Responses carry _published and _modified for versioned classes, _title for everything, and _relations with the IDs of each multi-value relation on get, create and update.

Token claims

The manager signs these alongside the standard iat / exp. All are optional.

Claim Meaning
sub Email or ID of the member to act as. Defaults to gate-client's configured member.
scope read (default) or write.
classes Array of class names this token may touch.
actions Array of actions this token may call. Set on presigned tokens.

CryptographyService::generateJwt() in gate-manager already accepts a payload array, so no change is needed there:

Restricting access

Four gates apply, narrowest wins.

  1. denied_classes — never reachable. The security tables are denied by default; add your own.
  2. allowed_classes — if set, nothing outside the list is reachable.
  3. The token's classes claim.
  4. The model's own canView() / canEdit() / canCreate() / canDelete(), evaluated against the member the token acts as.

A class that is out of reach reports the same "unknown class" error as one that does not exist, so a caller cannot probe for what a site defines.

To refuse writes on a site entirely, regardless of what any token claims:

Notes on security


All versions of silverstripe-gate-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
silverstripe/framework Version ^6.0
firebase/php-jwt Version ^6.11 || ^7.0
guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package atwx/silverstripe-gate-api contains the following files

Loading the files please wait ...