Skip to content

Commit 7ca7654

Browse files
Merge pull request #80 from logangingerich/patch-4
Update README.md
1 parent 877d283 commit 7ca7654

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ public class UserAuthentication {
187187

188188
If the request is correctly authenticated, the token's claims are made available in `requestState.claims()`. Otherwise the reason for the token verification failure is given by `requestState.reason()`.
189189

190+
### Machine Authentication
191+
192+
The SDK also supports machine-to-machine authentication through machine tokens. To authenticate machine requests, specify the accepted token types when building the authentication options:
193+
194+
```java
195+
import java.net.http.HttpRequest;
196+
import com.clerk.backend_api.helpers.security.AuthenticateRequest;
197+
import com.clerk.backend_api.helpers.security.models.AuthenticateRequestOptions;
198+
import com.clerk.backend_api.helpers.security.models.RequestState;
199+
import java.util.Arrays;
200+
201+
public class MachineAuthentication {
202+
203+
public static boolean isAuthenticated(HttpRequest request) {
204+
RequestState requestState = AuthenticateRequest.authenticateRequest(request, AuthenticateRequestOptions
205+
.secretKey(System.getenv("CLERK_SECRET_KEY"))
206+
.acceptsTokens(Arrays.asList("oauth_token"))
207+
.build());
208+
return requestState.isSignedIn();
209+
}
210+
}
211+
```
190212

191213
<!-- Start Available Resources and Operations [operations] -->
192214
## Available Resources and Operations

0 commit comments

Comments
 (0)