panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

Authorization Example Sample Code #265

Closed a3986 closed 4 years ago

a3986 commented 4 years ago

Hi,

I am using keycloak for my authentication and authorization purposes and using Angular as frontend and NodeJS as backend.

I am able to do the authentication using this library in node js but I am not able to figure out, how to do the authorization using the same.

I have created different resources, scopes in keycloak and also attached different permissions but could not make it work using this library.

It would be great, if someone could point me to a complete example on how scope or resource based authorization could be done using the library.

Last but not least, thank you for the library :)

panva commented 4 years ago

This is not a Resource Server library. You can merely request resources according to your IdP’s scheme by adding authorization request parameters.

a3986 commented 4 years ago

This is not a Resource Server library. You can merely request resources according to your IdP’s scheme by adding authorization request parameters.

Thanks for your response. Is there an example on how this is done? I was expecting a 403 error on requesting a resource if user does not have access to it.

panva commented 4 years ago

Once again, that is not the responsibility of this library, its an openid connect client, not a resource server. Its job is to give you means to establish an end-user session and accomodate requesting claims/tokens from the authorization server.

roggervalf commented 4 years ago

I could suggest using https://www.npmjs.com/package/iam-policies in a middleware. Also in backend you should check if token is valid from your provider, get the userId and so on.