Skip to content

Commit 6cb9f12

Browse files
committed
Added JWT example to OIDC for Services (#8915)
1 parent 42c5b82 commit 6cb9f12

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/src/main/asciidoc/security-openid-connect.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,41 @@ public class AdminResource {
139139
}
140140
----
141141

142+
Injection of the `SecurityIdentity` is supported in both `@RequestScoped` and `@ApplicationScoped` contexts.
143+
144+
=== Accessing JWT claims
145+
146+
If you need to access `JsonWebToken` claims, you may simply inject the token itself:
147+
148+
[source,java]
149+
----
150+
package org.acme.security.openid.connect;
151+
152+
import org.eclipse.microprofile.jwt.JsonWebToken;
153+
154+
import javax.annotation.security.RolesAllowed;
155+
import javax.ws.rs.GET;
156+
import javax.ws.rs.Path;
157+
import javax.ws.rs.Produces;
158+
import javax.ws.rs.core.MediaType;
159+
160+
@Path("/api/admin")
161+
public class AdminResource {
162+
163+
@Inject
164+
JsonWebToken jwt;
165+
166+
@GET
167+
@RolesAllowed("admin")
168+
@Produces(MediaType.TEXT_PLAIN)
169+
public String admin() {
170+
return "Access for subject " + jwt.getSubject() + " is granted";
171+
}
172+
}
173+
----
174+
175+
Injection of the `JsonWebToken` is supported in both `@RequestScoped` and `@ApplicationScoped` contexts.
176+
142177
== Configuring the application
143178

144179
The OpenID Connect extension allows you to define the adapter configuration using the `application.properties` file which should be located at the `src/main/resources` directory.

0 commit comments

Comments
 (0)