Skip to content

Commit 8b8d2ea

Browse files
committed
Rename default db name setter.
First draft of README and LICENSE.
1 parent 8b647b8 commit 8b8d2ea

5 files changed

Lines changed: 133 additions & 26 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Auth0
3+
Copyright (c) 2016 Auth0, Inc. <support@auth0.com> (http://auth0.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,101 @@
1-
# auth0-api-java
1+
# Auth0 Java
2+
3+
Java client library for the [Auth0](https://auth0.com) platform.
4+
5+
## Download
6+
7+
Get Auth0 Java via Maven:
8+
9+
```xml
10+
<dependency>
11+
<groupId>com.auth0</groupId>
12+
<artifactId>auth0-java</artifactId>
13+
<version>0.0.1</version>
14+
</dependency>
15+
```
16+
17+
or Gradle:
18+
19+
```gradle
20+
compile 'com.auth0:auth0-java:0.0.1'
21+
```
22+
23+
## Usage
24+
25+
First with your Auth0 account information
26+
27+
```java
28+
Auth0 auth0 = new Auth0("{YOUR_CLIENT_ID}", "{YOUR_DOMAIN}");
29+
```
30+
31+
and then ask `Auth0` object for the Authentication API Client
32+
33+
```java
34+
AuthenticationAPIClient client = auth0.newAuthenticationAPIClient();
35+
```
36+
37+
> Currently we only have a Authentication API Client, in future version we'll start adding Management API Client and methods.
38+
39+
### Authentication API
40+
41+
#### Making a request
42+
43+
Asynchronously
44+
45+
```java
46+
Auth0 auth0 = new Auth0("{YOUR_CLIENT_ID}", "{YOUR_DOMAIN}");
47+
AuthenticationAPIClient client = auth0.newAuthenticationAPIClient();
48+
49+
client.login("{username or email}", "{password}")
50+
.setConnection("{database connection name}")
51+
.start(new BaseCallback<Credentials>() {
52+
Override
53+
public void onSuccess(Credentials payload) { }
54+
55+
Override
56+
public void onFailure(Auth0Exception error) { }
57+
});
58+
```
59+
60+
Synchronously
61+
62+
```java
63+
Auth0 auth0 = new Auth0("{YOUR_CLIENT_ID}", "{YOUR_DOMAIN}");
64+
AuthenticationAPIClient client = auth0.newAuthenticationAPIClient();
65+
66+
Credentials credentials = client.login("{username or email}", "{password}")
67+
.setConnection("{database connection name}")
68+
.execute();
69+
```
70+
71+
## Documentation
72+
73+
For more information about [auth0](http://auth0.com) check our [documentation page](http://docs.auth0.com/).
74+
75+
## What is Auth0?
76+
77+
Auth0 helps you to:
78+
79+
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
80+
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
81+
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
82+
* Support for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
83+
* Analytics of how, when and where users are logging in.
84+
* Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules).
85+
86+
## Create a free Auth0 Account
87+
88+
1. Go to [Auth0](https://auth0.com) and click Sign Up.
89+
2. Use Google, GitHub or Microsoft Account to login.
90+
91+
## Issue Reporting
92+
93+
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
94+
95+
## Author
96+
97+
[Auth0](auth0.com)
98+
99+
## License
100+
101+
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.

lib/src/main/java/com/auth0/Auth0.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class Auth0 {
5151
private static final String DOT_AUTH0_DOT_COM = ".auth0.com";
5252

5353
private final String clientId;
54+
private final String clientSecret;
5455
private final String domainUrl;
5556
private final String configurationUrl;
5657
private Telemetry telemetry;
@@ -61,19 +62,30 @@ public class Auth0 {
6162
* @param domain of your Auth0 account
6263
*/
6364
public Auth0(String clientId, String domain) {
64-
this(clientId, domain, null);
65+
this(clientId, null, domain, null);
66+
}
67+
68+
/**
69+
* Creates a new object using clientId & domain
70+
* @param clientId of your Auth0 application
71+
* @param domain of your Auth0 account
72+
*/
73+
public Auth0(String clientId, String clientSecret, String domain) {
74+
this(clientId, clientSecret, domain, null);
6575
}
6676

6777
/**
6878
* Creates a new object using clientId, domain and configuration domain.
6979
* Useful when using a on-premise auth0 server that is not in the public cloud,
7080
* otherwise we recommend using the constructor {@link #Auth0(String, String)}
7181
* @param clientId of your Auth0 application
82+
* @param clientSecret of your Auth0 application. It can be null, specially if used for an Android application
7283
* @param domain of your Auth0 account
7384
* @param configurationDomain where Auth0's configuration will be fetched. By default is Auth0 public cloud
7485
*/
75-
public Auth0(String clientId, String domain, String configurationDomain) {
86+
public Auth0(String clientId, String clientSecret, String domain, String configurationDomain) {
7687
this.clientId = clientId;
88+
this.clientSecret = clientSecret;
7789
this.domainUrl = ensureUrlString(domain);
7890
this.configurationUrl = resolveConfiguration(configurationDomain, this.domainUrl);
7991
this.telemetry = new BaseTelemetry();
@@ -94,6 +106,13 @@ public String getDomainUrl() {
94106
return domainUrl;
95107
}
96108

109+
/**
110+
* @return your Auth0 account client secret or null
111+
*/
112+
public String getClientSecret() {
113+
return clientSecret;
114+
}
115+
97116
/**
98117
* @return your account configuration url
99118
*/

lib/src/main/java/com/auth0/authentication/AuthenticationAPIClient.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class AuthenticationAPIClient {
7575
private final ObjectMapper mapper;
7676
private final RequestFactory factory;
7777

78-
private String defaultDbConnection = DEFAULT_DB_CONNECTION;
78+
private String defaultDatabaseConnection = DEFAULT_DB_CONNECTION;
7979

8080
/**
8181
* Creates a new API client instance providing Auth0 account info.
@@ -86,18 +86,6 @@ public AuthenticationAPIClient(Auth0 auth0) {
8686
this(auth0, new OkHttpClient(), new ObjectMapper());
8787
}
8888

89-
/**
90-
* Creates a new API client instance providing Auth API and Configuration Urls different than the default. (Useful for on premise deploys).
91-
*
92-
* @param clientID Your application clientID.
93-
* @param baseURL Auth0's auth API endpoint
94-
* @param configurationURL Auth0's endpoint where App info can be retrieved.
95-
*/
96-
@SuppressWarnings("unused")
97-
public AuthenticationAPIClient(String clientID, String baseURL, String configurationURL) {
98-
this(new Auth0(clientID, baseURL, configurationURL));
99-
}
100-
10189
private AuthenticationAPIClient(Auth0 auth0, OkHttpClient client, ObjectMapper mapper) {
10290
this.auth0 = auth0;
10391
this.client = client;
@@ -127,20 +115,20 @@ public void setUserAgent(String userAgent) {
127115
}
128116

129117
/**
130-
* Set the default DB connection name used. By default is 'Username-Password-Authentication'
118+
* Set the default Auth0 database connection name used. By default is 'Username-Password-Authentication'
131119
*
132-
* @param defaultDbConnection name to use on every login with DB connection
120+
* @param defaultDatabaseConnection name to use on every login with DB connection
133121
*/
134-
public void setDefaultDbConnection(String defaultDbConnection) {
135-
this.defaultDbConnection = defaultDbConnection;
122+
public void setDefaultDatabaseConnection(String defaultDatabaseConnection) {
123+
this.defaultDatabaseConnection = defaultDatabaseConnection;
136124
}
137125

138126
/**
139127
* Log in a user with email/username and password using a DB connection.
140128
* Example usage:
141129
* <pre><code>
142130
* client.login("{username or email}", "{password}")
143-
* .setConnection("second-database")
131+
* .setConnection("{database connection name}")
144132
* .start(new BaseCallback<Credentials>() {
145133
* {@literal@}Override
146134
* public void onSuccess(Credentials payload) { }
@@ -308,7 +296,7 @@ public DatabaseConnectionRequest<DatabaseUser> createUser(String email, String p
308296
.set(USERNAME_KEY, username)
309297
.set(EMAIL_KEY, email)
310298
.set(PASSWORD_KEY, password)
311-
.setConnection(defaultDbConnection)
299+
.setConnection(defaultDatabaseConnection)
312300
.setClientId(getClientId())
313301
.asDictionary();
314302
final ParameterizableRequest<DatabaseUser> request = factory.POST(url, client, mapper, DatabaseUser.class)
@@ -418,7 +406,7 @@ public DatabaseConnectionRequest<Void> requestChangePassword(String email) {
418406
final Map<String, Object> parameters = ParameterBuilder.newBuilder()
419407
.set(EMAIL_KEY, email)
420408
.setClientId(getClientId())
421-
.setConnection(defaultDbConnection)
409+
.setConnection(defaultDatabaseConnection)
422410
.asDictionary();
423411
final ParameterizableRequest<Void> request = factory.POST(url, client, mapper)
424412
.addParameters(parameters);
@@ -675,7 +663,7 @@ private AuthenticationRequest loginWithResourceOwner(Map<String, Object> paramet
675663

676664
final Map<String, Object> requestParameters = ParameterBuilder.newBuilder()
677665
.setClientId(getClientId())
678-
.setConnection(defaultDbConnection)
666+
.setConnection(defaultDatabaseConnection)
679667
.addAll(parameters)
680668
.asDictionary();
681669
return factory.authenticationPOST(url, client, mapper)

lib/src/test/java/com/auth0/Auth0Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void shouldBuildWithClientIdAndDomain() throws Exception {
5353

5454
@Test
5555
public void shouldBuildWithConfigurationDomainToo() throws Exception {
56-
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN, CONFIG_DOMAIN_CUSTOM);
56+
Auth0 auth0 = new Auth0(CLIENT_ID, null, DOMAIN, CONFIG_DOMAIN_CUSTOM);
5757
assertThat(auth0.getClientId(), equalTo(CLIENT_ID));
5858
assertThat(auth0.getDomainUrl(), equalTo("https://samples.auth0.com"));
5959
assertThat(auth0.getConfigurationUrl(), equalTo("https://config.mydomain.com"));

0 commit comments

Comments
 (0)