jelhub / scimgateway

Using SCIM protocol as a gateway for user provisioning to other endpoints
MIT License
176 stars 57 forks source link

Is it possible to set 401 or 403 status #100

Closed christinedraper closed 1 year ago

christinedraper commented 1 year ago

I'm using the auth.passThrough option, so I need to be able to handle returning 401 or 403 but I'm not sure how to do this - could you give me a pointer?

I've figured out that throwing an error with a name field ends up as a 400 with the scimType set to the name, except for uniqueness which returns 409. An error without a name is a 500. But I couldn't find an option to override the status.

jelhub commented 1 year ago

Plugin return error as exceptions that will be included in the SCIM error message. There is currently no good way to let scimgateway return plugin status code. As you mentioned, plugin can set err.name="uniqueness" that will result in status code 409 DuplicateKey

For auth.passThrough, status code 401 will be returned by scimgateway and prevent revealing SCIM error message if exception message returned by plugin contains: "statusCode":401

If you are using REST this will be out-of-the box. Using other protocol, you may as a workaround include text "statusCode":401 in the exception message.

Ref: https://github.com/jelhub/scimgateway/blob/master/lib/scimgateway.js#L322-L336

christinedraper commented 1 year ago

Thanks for the quick reply. It would be great to be able to return a 403, too.

jelhub commented 1 year ago

Now fixed in v4.2.11 Error message from plugin that contains string "statusCode":XXX will return HTTP status code XXX

christinedraper commented 1 year ago

Brilliant! I'll give it a go later this week.

jelhub commented 1 year ago

Please note:

v4.2.15

[Added]