public class AuthAPI
extends java.lang.Object
AuthAPI(String, String, String)
using the tenant domain, and the Application's client id and client secret.
This class is not entirely thread-safe:
A new immutable OkHttpClient
instance is being created with each instantiation, not sharing the thread pool
with any prior existing client instance.
Constructor and Description |
---|
AuthAPI(java.lang.String domain,
java.lang.String clientId,
java.lang.String clientSecret)
Create a new instance with the given tenant's domain, application's client id and client secret.
|
AuthAPI(java.lang.String domain,
java.lang.String clientId,
java.lang.String clientSecret,
HttpOptions options)
Create a new instance with the given tenant's domain, application's client id and client secret.
|
Modifier and Type | Method and Description |
---|---|
AuthorizeUrlBuilder |
authorizeUrl(java.lang.String redirectUri)
Creates an instance of the
AuthorizeUrlBuilder with the given redirect url. |
void |
doNotSendTelemetry()
Avoid sending Telemetry data in every request to the Auth0 servers.
|
AuthRequest |
exchangeCode(java.lang.String code,
java.lang.String redirectUri)
Creates a request to exchange the code obtained in the /authorize call using the 'Authorization Code' grant.
|
AuthRequest |
login(java.lang.String emailOrUsername,
char[] password)
Creates a log in request using the 'Password' grant and the given credentials.
|
AuthRequest |
login(java.lang.String emailOrUsername,
char[] password,
java.lang.String realm)
Creates a log in request using the 'Password Realm' grant and the given credentials.
|
AuthRequest |
login(java.lang.String emailOrUsername,
java.lang.String password)
Deprecated.
Use login(String, char[]) instead.
|
AuthRequest |
login(java.lang.String emailOrUsername,
java.lang.String password,
java.lang.String realm)
Deprecated.
Use login(String, char[], String) instead.
|
LogoutUrlBuilder |
logoutUrl(java.lang.String returnToUrl,
boolean setClientId)
Creates an instance of the
LogoutUrlBuilder with the given return-to url. |
AuthRequest |
renewAuth(java.lang.String refreshToken)
Creates a request to renew the authentication and get fresh new credentials using a valid Refresh Token and the 'refresh_token' grant.
|
AuthRequest |
requestToken(java.lang.String audience)
Creates a request to get a Token for the given audience using the 'Client Credentials' grant.
|
Request |
resetPassword(java.lang.String email,
java.lang.String connection)
Request a password reset for the given email and database connection.
|
Request<java.lang.Void> |
revokeToken(java.lang.String refreshToken)
Creates a request to revoke an existing Refresh Token.
|
void |
setLoggingEnabled(boolean enabled)
Whether to enable or not the current HTTP Logger for every Request, Response and other sensitive information.
|
void |
setTelemetry(Telemetry telemetry)
Setter for the Telemetry to send in every request to Auth0.
|
SignUpRequest |
signUp(java.lang.String email,
char[] password,
java.lang.String connection)
Creates a sign up request with the given credentials and database connection.
|
SignUpRequest |
signUp(java.lang.String email,
java.lang.String username,
char[] password,
java.lang.String connection)
Creates a sign up request with the given credentials and database connection.
|
SignUpRequest |
signUp(java.lang.String email,
java.lang.String password,
java.lang.String connection)
Deprecated.
Use signUp(String, char[], String) instead.
|
SignUpRequest |
signUp(java.lang.String email,
java.lang.String username,
java.lang.String password,
java.lang.String connection)
Deprecated.
Use signUp(String, String, char[], String) instead.
|
Request<UserInfo> |
userInfo(java.lang.String accessToken)
Request the user information related to the access token.
|
public AuthAPI(java.lang.String domain, java.lang.String clientId, java.lang.String clientSecret, HttpOptions options)
HttpOptions
that will be used to configure the networking client.domain
- tenant's domain.clientId
- the application's client id.clientSecret
- the application's client secret.options
- configuration options for this client instance.AuthAPI(String, String, String)
public AuthAPI(java.lang.String domain, java.lang.String clientId, java.lang.String clientSecret)
domain
- tenant's domain.clientId
- the application's client id.clientSecret
- the application's client secret.public void doNotSendTelemetry()
public void setTelemetry(Telemetry telemetry)
telemetry
- to send in every request to Auth0public void setLoggingEnabled(boolean enabled)
enabled
- whether to enable the HTTP logger or not.public AuthorizeUrlBuilder authorizeUrl(java.lang.String redirectUri)
AuthorizeUrlBuilder
with the given redirect url.
i.e.:
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
String url = auth.authorizeUrl("https://me.auth0.com/callback")
.withConnection("facebook")
.withAudience("https://api.me.auth0.com/users")
.withScope("openid contacts")
.withState("my-custom-state")
.build();
redirectUri
- the redirect_uri value to set, white-listed in the Application settings. Must be already URL Encoded.AuthorizeUrlBuilder
to configure.public LogoutUrlBuilder logoutUrl(java.lang.String returnToUrl, boolean setClientId)
LogoutUrlBuilder
with the given return-to url.
i.e.:
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
String url = auth.logoutUrl("https://me.auth0.com/home", true)
.useFederated(true)
.withAccessToken("A9CvPwFojaBIA9CvI");
returnToUrl
- the redirect_uri value to set, white-listed in the Application settings. Must be already URL Encoded.setClientId
- whether the client_id value must be set or not. This affects the white-list that the Auth0's Dashboard uses to validate the returnTo url.LogoutUrlBuilder
to configure.public Request<UserInfo> userInfo(java.lang.String accessToken)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
UserInfo result = auth.userInfo("A9CvPwFojaBIA9CvI").execute();
} catch (Auth0Exception e) {
//Something happened
}
accessToken
- a valid access token belonging to an API signed with RS256 algorithm and containing the scope 'openid'.public Request resetPassword(java.lang.String email, java.lang.String connection)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
auth.resetPassword("[email protected]", "db-connection").execute();
} catch (Auth0Exception e) {
//Something happened
}
email
- the email associated to the database user.connection
- the database connection where the user was created.@Deprecated public SignUpRequest signUp(java.lang.String email, java.lang.String username, java.lang.String password, java.lang.String connection)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
Map<String, String> fields = new HashMap<String, String>();
fields.put("age", "25);
fields.put("city", "Buenos Aires");
auth.signUp("[email protected]", "myself", "topsecret", "db-connection")
.setCustomFields(fields)
.execute();
} catch (Auth0Exception e) {
//Something happened
}
email
- the desired user's email.username
- the desired user's username.password
- the desired user's password.connection
- the database connection where the user is going to be created.public SignUpRequest signUp(java.lang.String email, java.lang.String username, char[] password, java.lang.String connection)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
Map<String, String> fields = new HashMap<String, String>();
fields.put("age", "25);
fields.put("city", "Buenos Aires");
auth.signUp("[email protected]", "myself", new char[]{'s','e','c','r','e','t'}, "db-connection")
.setCustomFields(fields)
.execute();
} catch (Auth0Exception e) {
//Something happened
}
email
- the desired user's email.username
- the desired user's username.password
- the desired user's password.connection
- the database connection where the user is going to be created.@Deprecated public SignUpRequest signUp(java.lang.String email, java.lang.String password, java.lang.String connection)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
Map<String, String> fields = new HashMap<String, String>();
fields.put("age", "25);
fields.put("city", "Buenos Aires");
auth.signUp("[email protected]", "topsecret", "db-connection")
.setCustomFields(fields)
.execute();
} catch (Auth0Exception e) {
//Something happened
}
email
- the desired user's email.password
- the desired user's password.connection
- the database connection where the user is going to be created.public SignUpRequest signUp(java.lang.String email, char[] password, java.lang.String connection)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
Map<String, String> fields = new HashMap<String, String>();
fields.put("age", "25);
fields.put("city", "Buenos Aires");
auth.signUp("[email protected]", new char[]{'s','e','c','r','e','t'}, "db-connection")
.setCustomFields(fields)
.execute();
} catch (Auth0Exception e) {
//Something happened
}
email
- the desired user's email.password
- the desired user's password.connection
- the database connection where the user is going to be created.@Deprecated public AuthRequest login(java.lang.String emailOrUsername, java.lang.String password)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.login("[email protected]", "topsecret")
.setScope("openid email nickname")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
emailOrUsername
- the identity of the user.password
- the password of the user.public AuthRequest login(java.lang.String emailOrUsername, char[] password)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.login("[email protected]", new char[]{'s','e','c','r','e','t})
.setScope("openid email nickname")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
emailOrUsername
- the identity of the user.password
- the password of the user.@Deprecated public AuthRequest login(java.lang.String emailOrUsername, java.lang.String password, java.lang.String realm)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.login("[email protected]", "topsecret", "my-realm")
.setAudience("https://myapi.me.auth0.com/users")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
emailOrUsername
- the identity of the user.password
- the password of the user.realm
- the realm to use.public AuthRequest login(java.lang.String emailOrUsername, char[] password, java.lang.String realm)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.login("[email protected]", new char[]{'s','e','c','r','e','t'}, "my-realm")
.setAudience("https://myapi.me.auth0.com/users")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
emailOrUsername
- the identity of the user.password
- the password of the user.realm
- the realm to use.public AuthRequest requestToken(java.lang.String audience)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.requestToken("https://myapi.me.auth0.com/users")
.setRealm("my-realm")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
audience
- the audience of the API to request access to.public Request<java.lang.Void> revokeToken(java.lang.String refreshToken)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
auth.revokeToken("ej2E8zNEzjrcSD2edjaE")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
refreshToken
- the refresh token to revoke.public AuthRequest renewAuth(java.lang.String refreshToken)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.renewAuth("ej2E8zNEzjrcSD2edjaE")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
refreshToken
- the refresh token to use to get fresh new credentials.public AuthRequest exchangeCode(java.lang.String code, java.lang.String redirectUri)
AuthAPI auth = new AuthAPI("me.auth0.com", "B3c6RYhk1v9SbIJcRIOwu62gIUGsnze", "2679NfkaBn62e6w5E8zNEzjr-yWfkaBne");
try {
TokenHolder result = auth.exchangeCode("SnWoFLMzApDskr", "https://me.auth0.com/callback")
.setScope("openid name nickname")
.execute();
} catch (Auth0Exception e) {
//Something happened
}
code
- the authorization code received from the /authorize call.redirectUri
- the redirect uri sent on the /authorize call.