REST Authentication Guide
people found this article helpful
The purpose of this article is to serve as a reference guide for the authentication for REST APIs within OCS Service.
Various REST APIs within the application can be configured to require authorization in order to be used.
OCS Service REST APIs utilize OAuth2 as the standard authorization protocol. As of v29.00, the client credentials and password flow are supported; older versions of OCS Service prior to v29.00 only support the OAuth2 password flow.
Prerequisites
This needs to be done by the MINTRA Technical Team
Install OCS Service
- Set the
Use REST APIsetting to true via the OCS Config Editor to enable the REST API service host - Set the
REST Service URLsetting to an appropriate URL e.g.https://ocsapi.contoso.com - Set the
REST Service Portsetting to an appropriate and available port on the hosting server - Set the
SSL Certificate Thumbprintsetting to the corresponding SSL certificate thumbprint
Configuration: OAuth2
As of v30.00, authenticating via Personal Access Tokens (PATs) is the default authentication scheme.
The OAuth protocol is still supported for backwards compatibility, but is disabled by default and must be switched on.
Enabling the OAuth Protocol
If you wish to enable the OAuth protocol, simply set the Enable OAuth Protocol to true.
Conversely, the OAuth protocol can be disabled by setting the Enable OAuth Protocol option to false.
Adding Service Users
In order to authenticate via OAuth, one or more Service Users must be created within OCS Service’s settings.
A Service User requires a username (client ID) and password (client secret) to be created.
To access an installation’s users, right click the desired installation in the Services tab and select Open Service Users.
Opening the Service Users tab via the Services list:

The OCS Config Editor will switch to the Service Users tab, displaying users that have already been created.
Preview of the Service Users tab:

Click the Add new user button at the bottom of the tab, this will add a new user to the table.
Adding a new Service User:

Update the User Name and Password as appropriate, ensuring to store these credentials in the appropriate location within Keeper.
Once all necessary changes have been made, click Save at the bottom of the tab.
Authentication
Personal Access Tokens
As of v30.00, Personal Access Tokens (PATs) are considered the default form of authentication.
PATs are created and managed in OCS HR, as they are associated to application users. When a PAT is generated for or, on behalf of, a user it will inherit the granted privileges the user has.
In order to authenticate using a Personal Access Token (PAT), it must be provided in the Authorization header in your request.
The Authorization header value must be prefixed with apiKey e.g. apiKey {Key} or 'Authorization: apiKey {Key}'.
An example request can be found below:

When an API key is provided, OCS Service will consult the privileges that have been granted to the associated user of the provided PAT before validating whether they have access to the requested resource or not.
Privileges are not cached and, if required, can be updated in OCS HR to resolve access issues in real time.
OAuth2 Protocol
When authenticating via the OAuth2 protocol, you may use one authentication via the client credentials or password grant flows.
Most REST operations within OCS Service require a Bearer token to authenticate and complete successfully.
An authorization token can be fetched by sending a POST request to the token endpoint: https://{Host}:{Port}/restws/services/token
Password Grant Flow
To authenticate using a username and password, your request must have a form-encoded (application/x-www-form-urlencoded) body containing the “password” grant type, username and password for your OCS Service REST user.
An example request via the password flow can be found below:

Client Credentials Flow
Important: OCS Service v29.00+ also supports authentication via the OAuth2 client credentials flow. Versions prior v29.00 to this must use the password grant flow. If you are working with an older version of OCS Service, ignore the following information.
To authenticate using a client ID and secret, your request must have a form-encoded (application/x-www-form-urlencoded) body containing the client_credentials grant type, a client ID and secret for your Service User.
An example request via the client credentials flow can be found below:

Access Token Response
If your request is valid and successful, you should receive a 200 OK response from the token endpoint along with an access token:

Once you have your access token, you must supply the token in an Authorization header for your requests:
