Search code examples
javaoauth-2.0azure-active-directoryjersey

Oauth2 Resource Server + Azure AD + Java Code (Non Spring Boot/Framework)


Is there any solutions available to implement Oauth2 Resource Server using Azure AD without the spring boot/security frameworks. All examples I am finding are done in spring boot.

I have a java web application project which uses Jersey framework. I am trying to find some java code/sdk which will help to implement this.

Thanks in advance


Solution

  • Sometimes use of a library works better than a framework like Spring, as long as you understand the security principles.

    An OAuth secured API should just need to validate JWTs and this applies to those issued by Azure AD or any other provider, since the security involved is standards based.

    Have a look at this code example which uses a respected Java library. The example is in Kotlin but you will find it trivial to integrate into a Java API.

    You will need to pass the result of access token validation (scopes and claims) to the API logic, then use these values for domain specific authorization. It is common to use a request attribute for this.

    Azure AD tokens have a few peculiarities, mostly on the client side, so post back if you have any follow up questions.