File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,47 @@ fetch('/api/v1/projects/createProject', {
218
218
})
219
219
` ` `
220
220
221
+ # # Authenication via silverstripe-apikeys
222
+
223
+ If you would prefer to use API keys rather than JWT tokens, you can use
224
+ https://github.com/sminnee/silverstripe-apikey and configure it as a route
225
+ specific middleware
226
+
227
+ ` ` ` yml
228
+ SilverStripe\C ore\I njector\I njector:
229
+ ApiRouteMiddleware:
230
+ class: SilverStripe\C ontrol\M iddleware\R equestHandlerMiddlewareAdapter
231
+ properties:
232
+ RequestHandler: '%$MyProjectApi'
233
+ Middlewares:
234
+ CustomMiddleware: '%$ApiKeyRequestMiddleware'
235
+ MyProjectApi:
236
+ class: MyProjectApi
237
+ ApiKeyRequestMiddleware:
238
+ class: Sminnee\A piKey\A piKeyRequestMiddleware
239
+ SilverStripe\C ontrol\D irector:
240
+ rules:
241
+ api:
242
+ Controller: '%$ApiRouteMiddleware'
243
+
244
+ ` ` `
245
+
246
+ Out of the box, the silverstripe-apikey module will not throw an error if
247
+ no API key is provided (but it will if a wrong one is). So in the short term
248
+ you're best to double check and handle if the API key is not provided
249
+
250
+ ```
251
+ public function projects()
252
+ {
253
+ if (!$this->ensureUserLoggedIn()) {
254
+ return $this->failure(401);
255
+ }
256
+
257
+ // ..
258
+ }
259
+ ```
260
+
261
+
221
262
## UUIDs
222
263
223
264
https://stackoverflow.com/questions/56576985/is-it-a-bad-practice-to-expose-the-database-id-to-the-client-in-your-rest-api/56577271
You can’t perform that action at this time.
0 commit comments