Skip to content

Commit d81fdc1

Browse files
committed
Release 0.0.1
1 parent 7306f8a commit d81fdc1

File tree

11 files changed

+161
-5
lines changed

11 files changed

+161
-5
lines changed

.codecov.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
coverage:
2+
precision: 2
3+
round: down
4+
range: "70...100"
5+
status:
6+
patch:
7+
default:
8+
if_no_uploads: error
9+
changes: true
10+
project:
11+
default:
12+
target: auto
13+
if_no_uploads: error
14+
comment: false

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,3 @@ modules.xml
122122

123123
# End of https://www.gitignore.io/api/intellij+iml
124124

125-
.idea/*

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: java
2+
jdk:
3+
- openjdk7
4+
- oraclejdk7
5+
- oraclejdk8
6+
before_cache:
7+
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
8+
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
9+
sudo: false
10+
cache:
11+
directories:
12+
- $HOME/.gradle/caches/
13+
- $HOME/.gradle/wrapper/
14+
script:
15+
- "./gradlew clean check jacocoTestReport --continue"
16+
after_success:
17+
- bash <(curl -s https://codecov.io/bash)
18+
branches:
19+
only:
20+
- master

CHANGELOG.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Change Log
2+
3+
## [0.0.1](https://github.com/auth0/Guardian.java/tree/0.0.1) (2017-03-10)
4+
5+
First release of Guardian for Java
6+
7+
### Install
8+
9+
Get Guardian Java via Maven:
10+
11+
```xml
12+
<dependency>
13+
<groupId>com.auth0</groupId>
14+
<artifactId>guardian</artifactId>
15+
<version>0.0.1</version>
16+
</dependency>
17+
```
18+
19+
or Gradle:
20+
21+
```gradle
22+
compile 'com.auth0:guardian:0.0.1'
23+
```
24+
25+
### Usage
26+
27+
Create an instance of `Guardian` using you Guardian URL:
28+
29+
```java
30+
Guardian guardian = new Guardian("https://<tenant>.guardian.auth0.com");
31+
```
32+
33+
Obtain an enrollment ticket from API2:
34+
35+
```java
36+
String enrollmentTicket = "Ag1qX7vZVBvyTKhFwrkzaCH2M8vn5b6c";
37+
```
38+
39+
#### Enrollment
40+
41+
Use the ticket and `EnrollmentType.TOTP()` to request an TOTP enrollment, or `EnrollmentType.SMS()` and the phone number
42+
for an SMS enrollment.
43+
44+
For TOTP you must ask for the TOTP URI to show to the user in the QR code.
45+
46+
```java
47+
Transaction enrollmentTransaction;
48+
try {
49+
enrollmentTransaction = guardian
50+
.requestEnroll(enrollmentTicket, EnrollmentType.TOTP());
51+
// or .requestEnroll(enrollmentTicket, EnrollmentType.SMS("+549XXXXXXXX58"));
52+
53+
// Only for TOTP: use the TOTP URI to create a QR and scan with an app
54+
String totpURI = enrollmentTransaction.totpURI("Username", "Issuer");
55+
System.out.println(totpURI);
56+
57+
} catch (IOException e) {
58+
// connection issue, might be internet (or invalid certificates for example)
59+
} catch (GuardianException e) {
60+
if (e.isAlreadyEnrolled()) {
61+
// the user was already enrolled
62+
} else if (e.isInvalidToken()) {
63+
// the ticket is not valid anymore, or was already used
64+
} else {
65+
// some other guardian error, check the message
66+
}
67+
}
68+
```
69+
70+
#### Transaction storage
71+
72+
`Transaction` implements `java.io.Serializable` interface so you can save and restore it easily.
73+
74+
> The transaction contains sensitive information like the transaction token and the recovery code. Keep in mind this
75+
> when considering possible storage options.
76+
77+
#### Confirm enrollment
78+
79+
Restore the enrollment transaction from wherever you saved it, and use it together with the OTP that the user inputs to
80+
confirm the enrollment, whether it's TOTP or SMS.
81+
82+
If the OTP was valid, the enrollment is confirmed and you get an object that contains the recovery code.
83+
84+
```java
85+
// get the OTP from SMS or TOTP app
86+
String code = "123456";
87+
88+
try {
89+
Enrollment enrollment = guardian.confirmEnroll(enrollmentTransaction, code);
90+
91+
// Get the recovery code and show to the user
92+
String recoveryCode = enrollment.getRecoveryCode();
93+
System.out.println(recoveryCode);
94+
95+
} catch (IOException e) {
96+
// connection issue, might be internet (or invalid certificates for example)
97+
} catch (GuardianException e) {
98+
if (e.isInvalidToken()) {
99+
// the transaction is not valid anymore
100+
} else if (e.isInvalidOTP()) {
101+
// the OTP is not valid
102+
} else {
103+
// some other guardian error, check the message
104+
}
105+
}
106+
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ For SMS use `EnrollmentType.SMS()` and the phone number instead:
7878
Transaction enrollmentTransaction;
7979
try {
8080
enrollmentTransaction = guardian
81-
.requestEnroll(enrollmentTicket, EnrollmentType.SMS("+5493424217158"));
81+
.requestEnroll(enrollmentTicket, EnrollmentType.SMS("+549XXXXXXXX58"));
8282

8383
} catch (IOException e) {
8484
// connection issue, might be internet (or invalid certificates for example)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ logger.lifecycle("Using version ${version} for ${name}")
77

88
oss {
99
name 'guardian'
10-
repository 'guardian-java'
10+
repository 'Guardian.java'
1111
organization 'auth0'
1212
description 'Java library for Auth0\'s Guardian platform.'
1313

src/test/java/com/auth0/guardian/TestApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void main(String[] args) {
3636
Transaction enrollmentTransaction = null;
3737
try {
3838
enrollmentTransaction = guardian
39-
//.requestEnroll(enrollmentTicket, EnrollmentType.SMS("+5493424217158"));
39+
//.requestEnroll(enrollmentTicket, EnrollmentType.SMS("+549XXXXXXXX58"));
4040
.requestEnroll(enrollmentTicket, EnrollmentType.TOTP());
4141

4242
// Only for TOTP: use the TOTP URI to create a QR and scan with an app

src/test/java/com/auth0/guardian/networking/JsonConverterTest.java

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

8989
@Test
9090
public void shouldParseGenericMap() throws Exception {
91-
Map<Object, Object> parsed = converter.parse(Map.class, new StringReader("{\"someString\":\"theStringValue\",\"someNumber\":123.3}"));
91+
Map<String, Object> parsed = converter.parse(Map.class, new StringReader("{\"someString\":\"theStringValue\",\"someNumber\":123.3}"));
9292
assertThat(parsed, hasEntry("someString", (Object) "theStringValue"));
9393
assertThat(parsed, hasEntry("someNumber", (Object) 123.3));
9494
}

0 commit comments

Comments
 (0)