OAuth 2.0
- Last Updated: January 16, 2026
- 2 minute read
- MarkLogic Server
- Version 11.0
- Documentation
[v11.2.0 and up]
XCC supports connecting to XDBC app servers through OAuth.
After configuring an XDBC app server to use OAuth authentication, you must acquire an access token from the identity provider for use by the XCC client library.
Note:
-
The XCC client library is not responsible for acquiring, validating, maintaining, or renewing the JWT access token.
-
An access token that expires in the middle of a transaction will lead to an error.
You can then use ContentSourceFactory to create the instance of ContentSource.
The method newContentSource() is overloaded to provide multiple options to instantiate ContentSource.
One option is to use the following method overload signature:
static ContentSource newContentSource(
java.net.URI uri
)
The following example uses that method overload signature to supply the accessToken as part of the connection uri:
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
...
String host = "devhost";
int port = 8050;
String accessToken = "eyJhbGci..._adQssw5c";
String encodedAccessToken = URLEncoder.encode(accessToken, StandardCharsets.UTF_8.toString());
URI uri = new URI(
"xcc://" + host + ":" + port +
"?oauthtoken=" + encodedAccessToken
);
ContentSource contentSource = ContentSourceFactory.newContentSource(uri);
Session session = contentSource.newSession();
...
Another option is to pass these parameters separately using this method overload signature:
static ContentSource newContentSource(
java.lang.String host,
int port,
char[] authStr,
java.lang.String authType,
java.lang.String contentbaseName,
java.lang.String basePath
)
The following example uses that method overload signature to pass the parameters:
// configuration values that may be retrieved by some other mechanism
// outside scope of this guide.
String host = "devhost";
int port = 8050;
String accessToken = "eyJhbGci..._adQssw5c";
String authType = "OAUTH";
ContentSource contentSource =
ContentSourceFactory.newContentSource(
host,
port,
accessToken.toCharArray(),
authType,
null,
null
);
Session session = contentSource.newSession();
...
-
host: The fully qualified domain name or IPv4 address of your MarkLogic Server instance. -
accessToken: Your JWT access token. -
authType:OAUTH(for regular JWT Access Tokens). -
port: The configured port of your XDBC app server.
See Coding Basics for other required class imports.