Callback Handlers
Explore how to implement OAuth2 callback handlers in JakartaEE applications. Learn to validate CSRF tokens, exchange authorization codes for access tokens, and manage user sessions. Discover how to integrate CDI beans to retrieve user data like Google Calendar events through secured requests. Gain practical knowledge by creating servlets, JSF pages, and configuring web filters essential for OAuth2 workflows.
We'll cover the following...
We will continue working on the same OAuth2 example from the previous lesson.
Create a callback handler
Let’s go ahead and create the CallbackServlet.java in the Maven oauth2 directory src/main/java/be/rubus/workshop/oauth2:
Explanation
Lines 1 and 2: We creates the
CallbackServlet.Lines 25–31: Using the
doGet()method, we check the CSRF token.Lines 33–46: We exchange the authorization code for an access token (using the
ScribeJavapackages for imports), store the token within the session, and redirect to the original user-requested page.
Create Bean to retrieve data
We create a CDI bean that can ...