I started with my path with APIs, and I want to share my experience securing APIs using RBAC.
Before anything a few clarifications:
- APIM–>API Management
- ROPG–>Resource Owner Password Grant
- OIDC–>OpenID Connect
- RBAC–>Role Based Access Control
- SCBR–>SAP Cloud Business Rules
As you may know the users are assigned to roles in the Idp to restrict access , and APIs resources are assigned to scopes to restrict consumption, but these two concepts are not connected at all.
In complex scenarios you could need to secure APIs resources using user roles, and the main question here is “how to do it?”, my personal answer is using SCBR to translate User Roles to Allowed Scopes.
- Idp: Okta to handle user authentication ( OIDC APIs ).
- OAuth API:authenticate user, translate user roles to scopes & generate access tokens
- Secured API:verify token, and custom scopes
- SCBP: handle the translation between user roles & custom scopes
-Okta user & roles:
-SAP Cloud Business Rules:
-OAuth API Policies:
- Authenticate user in Idp using OIDC via ROPG
- Get Groups from JWT
- Generate request payload for SCBR
- Get X-CSRF-Token for SCBR
- Call to SCBR API to get the scopes
- Parse the scopes
- Generate token including allowed scopes
-Secured API resources:
Policies in PreFlow:
- Verify OAuth token & get custom scopes attached to it
- Generate dynamic scope and validate it
- Raise exception if the scope is not allowed
Let’s see it in action when the requested scope is not allowed to consume a resource
Debugging OAuth API:
Debuging secured API:
Verify Token Policy:
Raise Exception Policy:
As you can see it is possible to handle scopes dynamically in your APIs using user roles.
Not forget be curious 😉