Skip to content

Commit 5d56e67

Browse files
committed
rename AuthAPI methods.
1 parent c9adc59 commit 5d56e67

3 files changed

Lines changed: 78 additions & 82 deletions

File tree

README.md

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,28 @@ AuthAPI auth = new AuthAPI("{YOUR_DOMAIN}", "{YOUR_CLIENT_ID}", "{YOUR_CLIENT_SE
4242

4343
Creates an `AuthorizeUrlBuilder` to authenticate the user with an OAuth provider. The `redirectUri` must be white-listed in the "Allowed Callback URLs" section of the Client Settings. Parameters can be added to the final url by using the builder methods. When ready, call `build()` and obtain the Url.
4444

45-
`AuthorizeUrlBuilder authorize("{CONNECTION}", "{REDIRECT_URI}")`
45+
`AuthorizeUrlBuilder authorizeUrl("{REDIRECT_URI}")`
4646

4747
Example:
4848
```java
49-
AuthorizeUrlBuilder builder = auth.authorize("facebook", "https://me.auth0.com/callback");
50-
builder.withAudience("https://api.me.auth0.com/users");
51-
builder.withScope("openid contacts");
52-
builder.withState("state123");
53-
54-
String url = builder.build();
55-
// https://me.auth0.com/authorize?redirect_uri=https://me.auth0.com/callback&response_type=code&client_id=iaih2D7AC56kksdkPtWAsjI3li&audience=https://api.me.auth0.com/users&scope=openid%20contacts&connection=facebook&state=state123
49+
String url = auth.authorizeUrl("https://me.auth0.com/callback")
50+
.withConnection("facebook")
51+
.withAudience("https://api.me.auth0.com/users")
52+
.withScope("openid contacts")
53+
.withState("state123")
54+
.build();
5655
```
5756

5857
### Logout - /v2/logout
5958
Creates a `LogoutUrlBuilder` to log out the user. The `returnToUrl` must be white-listed in the "Allowed Logout URLs" section of the Client Settings. Parameters can be added to the final url by using the builder methods. When ready, call `build()` and obtain the Url.
6059

61-
`LogoutUrlBuilder logout("{RETURN_TO_URL}", "{SEND_CLIENT_ID}")`
60+
`LogoutUrlBuilder logoutUrl("{RETURN_TO_URL}", "{SEND_CLIENT_ID}")`
6261

6362
Example:
6463
```java
65-
LogoutUrlBuilder builder = auth.logout("https://me.auth0.com/home", true);
66-
builder.useFederated(true);
67-
builder.withAccessToken("aToKen");
68-
69-
String url = builder.build();
70-
// https://me.auth0.com/v2/logout?returnTo=https://me.auth0.com/home&client_id=iaih2D7AC56kksdkPtWAsjI3li&access_token=aToKen&federated=
64+
String url = auth.logoutUrl("https://me.auth0.com/home", true)
65+
.useFederated(true)
66+
.withAccessToken("aToKen");
7167
```
7268

7369
### UserInfo - /userinfo
@@ -129,15 +125,15 @@ try {
129125
}
130126
```
131127

132-
### Log In with Authorization Code - /oauth/token
128+
### Exchange the Authorization Code - /oauth/token
133129

134-
Creates a new request to log in the user with a `code` previously obtained by calling the /authorize endpoint. The redirect uri must be the one sent in the /authorize call.
130+
Creates a new request to exchange the `code` previously obtained by calling the /authorize endpoint. The redirect uri must be the one sent in the /authorize call.
135131

136-
`AuthRequest loginWithAuthorizationCode("{CODE}", "{REDIRECT_URI}")`
132+
`AuthRequest exchangeCode("{CODE}", "{REDIRECT_URI}")`
137133

138134
Example:
139135
```java
140-
AuthRequest request = loginWithAuthorizationCode("asdfgh", "https://me.auth0.com/callback");
136+
AuthRequest request = exchangeCode("asdfgh", "https://me.auth0.com/callback");
141137
request.setAudience("https://api.me.auth0.com/users");
142138
request.setScope("openid contacts");
143139
try {
@@ -154,11 +150,11 @@ try {
154150

155151
Creates a new request to log in the user with `username` and `password`. The connection used is the one defined as "Default Directory" in the account settings.
156152

157-
`AuthRequest loginWithPassword("{USERNAME_OR_EMAIL}", "{PASSWORD}")`
153+
`AuthRequest login("{USERNAME_OR_EMAIL}", "{PASSWORD}")`
158154

159155
Example:
160156
```java
161-
AuthRequest request = loginWithPassword("me@domain.com", "password123");
157+
AuthRequest request = login("me@domain.com", "password123");
162158
request.setAudience("https://api.me.auth0.com/users");
163159
request.setScope("openid contacts");
164160
try {
@@ -175,11 +171,11 @@ try {
175171

176172
Creates a new request to log in the user with `username` and `password` using the Password Realm.
177173

178-
`AuthRequest loginWithPasswordRealm("{USERNAME_OR_EMAIL}", "{PASSWORD}", "{REALM}")`
174+
`AuthRequest login("{USERNAME_OR_EMAIL}", "{PASSWORD}", "{REALM}")`
179175

180176
Example:
181177
```java
182-
AuthRequest request = loginWithPasswordRealm("me@domain.com", "password123", "Username-Password-Authentication");
178+
AuthRequest request = login("me@domain.com", "password123", "Username-Password-Authentication");
183179
request.setAudience("https://api.me.auth0.com/users");
184180
request.setScope("openid contacts");
185181
try {
@@ -192,15 +188,15 @@ try {
192188
}
193189
```
194190

195-
### Log In with Client Credentials - /oauth/token
191+
### Request Token for Audience - /oauth/token
196192

197-
Creates a new request to log in the user using the Client Credentials.
193+
Creates a new request to get a Token for the given Audience.
198194

199-
`AuthRequest loginWithClientCredentials("{AUDIENCE}")`
195+
`AuthRequest requestToken("{AUDIENCE}")`
200196

201197
Example:
202198
```java
203-
AuthRequest request = loginWithClientCredentials("https://api.me.auth0.com/users");
199+
AuthRequest request = requestToken("https://api.me.auth0.com/users");
204200
request.setScope("openid contacts");
205201
try {
206202
TokenHolder holder = request.execute();

src/main/java/com/auth0/client/auth/AuthAPI.java

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private String createBaseUrl(String domain) {
9191
* @param redirectUri the redirect_uri value to set, white-listed in the client settings. Must be already URL Encoded.
9292
* @return a new instance of the {@link AuthorizeUrlBuilder} to configure.
9393
*/
94-
public AuthorizeUrlBuilder authorize(String redirectUri) {
94+
public AuthorizeUrlBuilder authorizeUrl(String redirectUri) {
9595
Asserts.assertNotNull(redirectUri, "redirect uri");
9696

9797
return AuthorizeUrlBuilder.newInstance(baseUrl, clientId, redirectUri);
@@ -104,15 +104,15 @@ public AuthorizeUrlBuilder authorize(String redirectUri) {
104104
* @param 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.
105105
* @return a new instance of the {@link AuthorizeUrlBuilder} to configure.
106106
*/
107-
public LogoutUrlBuilder logout(String returnToUrl, boolean setClientId) {
107+
public LogoutUrlBuilder logoutUrl(String returnToUrl, boolean setClientId) {
108108
Asserts.assertNotNull(returnToUrl, "return to url");
109109

110110
return LogoutUrlBuilder.newInstance(baseUrl, clientId, returnToUrl, setClientId);
111111
}
112112

113113

114114
/**
115-
* Request the user information related to this access token.
115+
* Request the user information related to the access token.
116116
*
117117
* @param accessToken a valid access token belonging to an API signed with RS256 algorithm and containing the scope 'openid'.
118118
* @return a Request to execute.
@@ -201,40 +201,14 @@ public SignUpRequest signUp(String email, String password, String connection) {
201201
return request;
202202
}
203203

204-
/**
205-
* Creates a new log in request using the 'Authorization Code' grant and the given code and redirect uri parameters.
206-
*
207-
* @param code the authorization code received from the /authorize call.
208-
* @param redirectUri the redirect uri sent on the /authorize call.
209-
* @return a Request to configure and execute.
210-
*/
211-
public AuthRequest loginWithAuthorizationCode(String code, String redirectUri) {
212-
Asserts.assertNotNull(code, "code");
213-
Asserts.assertNotNull(redirectUri, "redirect uri");
214-
215-
String url = HttpUrl.parse(baseUrl)
216-
.newBuilder()
217-
.addPathSegment(PATH_OAUTH)
218-
.addPathSegment(PATH_TOKEN)
219-
.build()
220-
.toString();
221-
TokenRequest request = new TokenRequest(client, url);
222-
request.addParameter(KEY_CLIENT_ID, clientId);
223-
request.addParameter(KEY_CLIENT_SECRET, clientSecret);
224-
request.addParameter(KEY_GRANT_TYPE, "authorization_code");
225-
request.addParameter("code", code);
226-
request.addParameter("redirect_uri", redirectUri);
227-
return request;
228-
}
229-
230204
/**
231205
* Creates a new log in request using the 'Password' grant and the given credentials.
232206
*
233207
* @param emailOrUsername the identity of the user.
234208
* @param password the password of the user.
235209
* @return a Request to configure and execute.
236210
*/
237-
public AuthRequest loginWithPassword(String emailOrUsername, String password) {
211+
public AuthRequest login(String emailOrUsername, String password) {
238212
Asserts.assertNotNull(emailOrUsername, "email or username");
239213
Asserts.assertNotNull(password, "password");
240214

@@ -261,7 +235,7 @@ public AuthRequest loginWithPassword(String emailOrUsername, String password) {
261235
* @param password the password of the user.
262236
* @return a Request to configure and execute.
263237
*/
264-
public AuthRequest loginWithPasswordRealm(String emailOrUsername, String password, String realm) {
238+
public AuthRequest login(String emailOrUsername, String password, String realm) {
265239
Asserts.assertNotNull(emailOrUsername, "email or username");
266240
Asserts.assertNotNull(password, "password");
267241
Asserts.assertNotNull(realm, "realm");
@@ -283,13 +257,13 @@ public AuthRequest loginWithPasswordRealm(String emailOrUsername, String passwor
283257
}
284258

285259
/**
286-
* Creates a new log in request using the 'Client Credentials' grant for the given audience.
260+
* Creates a new request using the 'Client Credentials' grant to get a Token for the given audience.
287261
* Default used realm and audience are defined in the "API Authorization Settings" in the account's advanced settings in the Auth0 Dashboard.
288262
*
289263
* @param audience the audience of the API to request access to.
290264
* @return a Request to configure and execute.
291265
*/
292-
public AuthRequest loginWithClientCredentials(String audience) {
266+
public AuthRequest requestToken(String audience) {
293267
Asserts.assertNotNull(audience, "audience");
294268

295269
String url = HttpUrl.parse(baseUrl)
@@ -305,4 +279,30 @@ public AuthRequest loginWithClientCredentials(String audience) {
305279
request.addParameter(KEY_AUDIENCE, audience);
306280
return request;
307281
}
282+
283+
/**
284+
* Creates a new request using the 'Authorization Code' grant to exchange the code obtained in the /authorize call.
285+
*
286+
* @param code the authorization code received from the /authorize call.
287+
* @param redirectUri the redirect uri sent on the /authorize call.
288+
* @return a Request to configure and execute.
289+
*/
290+
public AuthRequest exchangeCode(String code, String redirectUri) {
291+
Asserts.assertNotNull(code, "code");
292+
Asserts.assertNotNull(redirectUri, "redirect uri");
293+
294+
String url = HttpUrl.parse(baseUrl)
295+
.newBuilder()
296+
.addPathSegment(PATH_OAUTH)
297+
.addPathSegment(PATH_TOKEN)
298+
.build()
299+
.toString();
300+
TokenRequest request = new TokenRequest(client, url);
301+
request.addParameter(KEY_CLIENT_ID, clientId);
302+
request.addParameter(KEY_CLIENT_SECRET, clientSecret);
303+
request.addParameter(KEY_GRANT_TYPE, "authorization_code");
304+
request.addParameter("code", code);
305+
request.addParameter("redirect_uri", redirectUri);
306+
return request;
307+
}
308308
}

0 commit comments

Comments
 (0)