# Keycloak just as Authorization Server

**URL:** <https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824>\
**Category:** Miscellanaeous\
**Created:** [February 23, 2022, 12:42pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824 "2022-02-23T12:42:45Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 23, 2022, 12:42pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/1 "2022-02-23T12:42:45Z")

</div>

Hello Gurus, I liked the Keycloak as AuthZ server, in our ecosystem AuthN is very well established and many applications are already using it. I have to build a central Authorization service, Keycloak has all the feature, but I don’t want to federate it with IDPs.  
Is it possible or recommended to use Keycloak just as AuthZ server without anything related to AuthN.

Please share your thoughts/ concerns.

---

<div class="post-metadata">

**Author:** ![melancholia](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@melancholia](https://forum.keycloak.org/u/melancholia)\
**Post date:** [February 23, 2022, 4:37pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/2 "2022-02-23T16:37:15Z")

</div>

It is possible. Whether it is ideal or not, would very much depend on your use cases.

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 24, 2022, 1:36pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/3 "2022-02-24T13:36:01Z")

</div>

But does this possibility come with a lot of rider ? Is there anyway to remove the authentication part from KeyCloak?

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [February 24, 2022, 3:23pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/4 "2022-02-24T15:23:17Z")

</div>

Keycloak is an Identity Provider, thus a server/system made for authentication. Removing authentication parts from Keycloak would most probably result in chaos.

I’d suggest to better investigate in pure authorization solutions, perhaps something like [OPA](https://www.openpolicyagent.org/) or similar. Less stress and optimized for authorization.

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 24, 2022, 4:27pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/5 "2022-02-24T16:27:28Z")

</div>

Thanks dasniko, OPA looks promising, would you mind to suggest other competitors of it ? Like oso, ory , have you ever got chance to compare all these ?

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [February 24, 2022, 4:38pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/6 "2022-02-24T16:38:11Z")

</div>

I second @dasniko 's thoughts on the idea of removing the authn parts from Keycloak.

I am currently looking at Oso and Casbin. I can’t make a strong recommendation either way yet, but both appear to be current, well-supported projects with good communities.

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 24, 2022, 4:51pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/7 "2022-02-24T16:51:09Z")

</div>

Just to be clear, when I say remove, I did not mean removing authentication from code what I meant, not using authentication feature at all.

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [February 24, 2022, 5:33pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/8 "2022-02-24T17:33:59Z")

</div>

Without having the users in Keycloak, I can’t imagine how using the authorization feature alone would work. It assumes that you’ve got the users and Keycloak and you are using it for authentication.

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 24, 2022, 5:52pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/9 "2022-02-24T17:52:05Z")

</div>

Fair point, I was assuming user information can be provided via SPI, writing some custom code to lookup user via REST API. We have different application which maintains the user and provides a REST endpoint to fetch users detail. So we don’t need authentication from KeyCloak and don’t want users to be created in KeyCloak , just want to store Policies, Permissions and token generation from KeyCloak.

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [February 24, 2022, 7:17pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/10 "2022-02-24T19:17:12Z")

</div>

Technically, it‘s possible to implement a custom User Storage SPI and manage the authorization policies in KC. But this adds complexity and overhead to a system what is made for something different.  
And - TBH - the authorization services in Keycloak are one of the worst I ever saw, IMHO.

**Use the right tool for the right job!!**

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [February 24, 2022, 7:21pm UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/11 "2022-02-24T19:21:54Z")

</div>

Thanks dasniko, can’t agree more with you.

---

<div class="post-metadata">

**Author:** ![jrobinss](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jrobinss/32/113_2.png) [@jrobinss](https://forum.keycloak.org/u/jrobinss)\
**Post date:** [February 28, 2022, 11:55am UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/12 "2022-02-28T11:55:10Z")

</div>

First there is a question of vocabulary. I guess that what you call “authorization server” is what is called PDP, Policy Decision Point, in OAuth. In other words, it’s where you send a token, and it evaluates policies, and returns permissions.

The term “authorization server” can also be used to describe the server that provides the token. Should it be the identity server? Not necessarily, it can just delegate identification to some other server, or take a token as input (token exchange). _(to confuse matters, the endpoint for both usages is the same in Keycloak, it didn’t use to be)_

So you want to use Keycloak as a PDP and PMP (Policy Management Point, where you define the policies).

I’m actually curious as to whether that’s possible, even though I tend to agree with others that it’s not the primary purpose of Keycloak. You would need to only reference stuff from the JWT in your policies, whereas Keycloak policies can actually fetch stuff from user profiles, groups etc.

I have found problems with Keycloak as a policy evaluator (PDP): [oauth - Keycloak JavaScript APIs do not provide effective roles and attributes from groups - Stack Overflow](https://stackoverflow.com/questions/66921028/keycloak-javascript-apis-do-not-provide-effective-roles-and-attributes-from-grou)  
I have found problems with Keycloak as a token provider (as opposed to identity provider, see above): [Token exchange (external to internal) and mapping don’t work together - Miscellanaeous - Keycloak](http://forum.keycloak.org/t/token-exchange-external-to-internal-and-mapping-dont-work-together/12313)

I have not found any problems with Keycloak as an identity provider, complete with federation.

The main policy engine that I hear about is OPA. For a comparison with Casbin, there is this… [OPA vs Casbin · GitHub](https://gist.github.com/StevenACoffman/1644ec1157a793eb7d868aa22b260e91)  
(it reads a bit like a vi vs emacs page, they are very close 🙂 )

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [March 1, 2022, 5:28am UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/13 "2022-03-01T05:28:16Z")

</div>

Thanks jrobinss - You are right, I want to use Keycloak as PDP and PMP. Here is what I would like my AuthZ service to work.

1. Get OIDC token from IDP (Already have IDP in ecosystem, can’t use Keycloak for this purpose).
2. Make request to AuthZ service with OIDC token + Scopes of Target applications.
3. AuthZ service, takes the user info from token, looks for allowed scope and attach permission as claims.
4. If client has any protected resource like “views” “pages” it serve based on permissions inside token.
5. If client want to receive data from any data provider (target application), same token can be passed, if any target application still need finer level access details, it can make call to AuthZ server (PDP) with Token + Requested permission + Resource, based on these information PDP return allow/ no allow.

I liked OPA very much as it does what exactly I need PDP + PMP, only concern is, it runs as proxy inside sidecar. Not all applications in my ecosystem are built using Kubernetes , there few on google app engine as well.

I am open for any suggestion .

---

<div class="post-metadata">

**Author:** ![jrobinss](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jrobinss/32/113_2.png) [@jrobinss](https://forum.keycloak.org/u/jrobinss)\
**Post date:** [March 8, 2022, 10:10am UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/14 "2022-03-08T10:10:48Z")

</div>

If you just want Keycloak to act as PDP, I suppose you would still have to declare your IDP as an external IDP in Keycloak. If only because Keycloak needs to trust the token to evaluate the policies. And it will synch users in Keycloak automatically (choose “force synch” to forget about synch issues).

I have not tested this. If it doesn’t work, it would be because Keycloak is expecting a token from itself. In which case you need first token exchange, then evaluation. Things get more complicated than you wished for.

BTW does Keycloak validate the audience “aud” of the JWT? JWT validation is policies, sure, but also validation of expiration date, not-before date, audience etc.

---

<div class="post-metadata">

**Author:** ![Singha2](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/singha2/32/5143_2.png) [@Singha2](https://forum.keycloak.org/u/Singha2)\
**Post date:** [March 8, 2022, 10:24am UTC](https://forum.keycloak.org/t/keycloak-just-as-authorization-server/13824/15 "2022-03-08T10:24:28Z")

</div>

Thanks jrobniss - This explanation helps, appreciate your help.
