Skip to content

Commit 91a518b

Browse files
committedNov 29, 2023
Initial commit
0 parents  commit 91a518b

26 files changed

+771
-0
lines changed
 

‎.gitattributes

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.gradle
2+
build
3+
local.properties

‎.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"java.project.sourcePaths": ["./src/main/java"],
3+
"java.configuration.updateBuildConfiguration": "automatic"
4+
}

‎build.gradle

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
plugins {
2+
id 'java-library'
3+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
implementation 'com.google.code.gson:gson:2.10.1'
12+
implementation "com.nimbusds:nimbus-jose-jwt:7.8.1"
13+
14+
testImplementation 'junit:junit:4.13.2'
15+
}
16+
17+
nexusPublishing {
18+
repositories {
19+
sonatype {
20+
def Properties properties = new Properties()
21+
properties.load(project.rootProject.file("local.properties").newDataInputStream())
22+
23+
username.set(properties.getProperty("ossrhUsername"))
24+
password.set(properties.getProperty("ossrhPassword"))
25+
stagingProfileId.set(properties.getProperty("sonatypeStagingProfileId"))
26+
nexusUrl.set(uri(properties.getProperty("nexusUrl")))
27+
snapshotRepositoryUrl.set(uri(properties.getProperty("snapshotRepositoryUrl")))
28+
}
29+
}
30+
}

‎gradle/wrapper/gradle-wrapper.jar

62.2 KB
Binary file not shown.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

‎gradlew

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
#!/bin/sh
2+
3+
#
4+
# Copyright © 2015-2021 the original authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
##############################################################################
20+
#
21+
# Gradle start up script for POSIX generated by Gradle.
22+
#
23+
# Important for running:
24+
#
25+
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
26+
# noncompliant, but you have some other compliant shell such as ksh or
27+
# bash, then to run this script, type that shell name before the whole
28+
# command line, like:
29+
#
30+
# ksh Gradle
31+
#
32+
# Busybox and similar reduced shells will NOT work, because this script
33+
# requires all of these POSIX shell features:
34+
# * functions;
35+
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
36+
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
37+
# * compound commands having a testable exit status, especially «case»;
38+
# * various built-in commands including «command», «set», and «ulimit».
39+
#
40+
# Important for patching:
41+
#
42+
# (2) This script targets any POSIX shell, so it avoids extensions provided
43+
# by Bash, Ksh, etc; in particular arrays are avoided.
44+
#
45+
# The "traditional" practice of packing multiple parameters into a
46+
# space-separated string is a well documented source of bugs and security
47+
# problems, so this is (mostly) avoided, by progressively accumulating
48+
# options in "$@", and eventually passing that to Java.
49+
#
50+
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
51+
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
52+
# see the in-line comments for details.
53+
#
54+
# There are tweaks for specific operating systems such as AIX, CygWin,
55+
# Darwin, MinGW, and NonStop.
56+
#
57+
# (3) This script is generated from the Groovy template
58+
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
59+
# within the Gradle project.
60+
#
61+
# You can find Gradle at https://github.com/gradle/gradle/.
62+
#
63+
##############################################################################
64+
65+
# Attempt to set APP_HOME
66+
67+
# Resolve links: $0 may be a link
68+
app_path=$0
69+
70+
# Need this for daisy-chained symlinks.
71+
while
72+
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
73+
[ -h "$app_path" ]
74+
do
75+
ls=$( ls -ld "$app_path" )
76+
link=${ls#*' -> '}
77+
case $link in #(
78+
/*) app_path=$link ;; #(
79+
*) app_path=$APP_HOME$link ;;
80+
esac
81+
done
82+
83+
# This is normally unused
84+
# shellcheck disable=SC2034
85+
APP_BASE_NAME=${0##*/}
86+
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87+
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
88+
89+
# Use the maximum available, or set MAX_FD != -1 to use that value.
90+
MAX_FD=maximum
91+
92+
warn () {
93+
echo "$*"
94+
} >&2
95+
96+
die () {
97+
echo
98+
echo "$*"
99+
echo
100+
exit 1
101+
} >&2
102+
103+
# OS specific support (must be 'true' or 'false').
104+
cygwin=false
105+
msys=false
106+
darwin=false
107+
nonstop=false
108+
case "$( uname )" in #(
109+
CYGWIN* ) cygwin=true ;; #(
110+
Darwin* ) darwin=true ;; #(
111+
MSYS* | MINGW* ) msys=true ;; #(
112+
NONSTOP* ) nonstop=true ;;
113+
esac
114+
115+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116+
117+
118+
# Determine the Java command to use to start the JVM.
119+
if [ -n "$JAVA_HOME" ] ; then
120+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
121+
# IBM's JDK on AIX uses strange locations for the executables
122+
JAVACMD=$JAVA_HOME/jre/sh/java
123+
else
124+
JAVACMD=$JAVA_HOME/bin/java
125+
fi
126+
if [ ! -x "$JAVACMD" ] ; then
127+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
128+
129+
Please set the JAVA_HOME variable in your environment to match the
130+
location of your Java installation."
131+
fi
132+
else
133+
JAVACMD=java
134+
if ! command -v java >/dev/null 2>&1
135+
then
136+
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
137+
138+
Please set the JAVA_HOME variable in your environment to match the
139+
location of your Java installation."
140+
fi
141+
fi
142+
143+
# Increase the maximum file descriptors if we can.
144+
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145+
case $MAX_FD in #(
146+
max*)
147+
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148+
# shellcheck disable=SC2039,SC3045
149+
MAX_FD=$( ulimit -H -n ) ||
150+
warn "Could not query maximum file descriptor limit"
151+
esac
152+
case $MAX_FD in #(
153+
'' | soft) :;; #(
154+
*)
155+
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156+
# shellcheck disable=SC2039,SC3045
157+
ulimit -n "$MAX_FD" ||
158+
warn "Could not set maximum file descriptor limit to $MAX_FD"
159+
esac
160+
fi
161+
162+
# Collect all arguments for the java command, stacking in reverse order:
163+
# * args from the command line
164+
# * the main class name
165+
# * -classpath
166+
# * -D...appname settings
167+
# * --module-path (only if needed)
168+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
169+
170+
# For Cygwin or MSYS, switch paths to Windows format before running java
171+
if "$cygwin" || "$msys" ; then
172+
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
173+
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
174+
175+
JAVACMD=$( cygpath --unix "$JAVACMD" )
176+
177+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
178+
for arg do
179+
if
180+
case $arg in #(
181+
-*) false ;; # don't mess with options #(
182+
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183+
[ -e "$t" ] ;; #(
184+
*) false ;;
185+
esac
186+
then
187+
arg=$( cygpath --path --ignore --mixed "$arg" )
188+
fi
189+
# Roll the args list around exactly as many times as the number of
190+
# args, so each arg winds up back in the position where it started, but
191+
# possibly modified.
192+
#
193+
# NB: a `for` loop captures its iteration list before it begins, so
194+
# changing the positional parameters here affects neither the number of
195+
# iterations, nor the values presented in `arg`.
196+
shift # remove old arg
197+
set -- "$@" "$arg" # push replacement arg
198+
done
199+
fi
200+
201+
202+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204+
205+
# Collect all arguments for the java command:
206+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207+
# and any embedded shellness will be escaped.
208+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209+
# treated as '${Hostname}' itself on the command line.
210+
211+
set -- \
212+
"-Dorg.gradle.appname=$APP_BASE_NAME" \
213+
-classpath "$CLASSPATH" \
214+
org.gradle.wrapper.GradleWrapperMain \
215+
"$@"
216+
217+
# Stop when "xargs" is not available.
218+
if ! command -v xargs >/dev/null 2>&1
219+
then
220+
die "xargs is not available"
221+
fi
222+
223+
# Use "xargs" to parse quoted args.
224+
#
225+
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
226+
#
227+
# In Bash we could simply go:
228+
#
229+
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
230+
# set -- "${ARGS[@]}" "$@"
231+
#
232+
# but POSIX shell has neither arrays nor command substitution, so instead we
233+
# post-process each arg (as a line of input to sed) to backslash-escape any
234+
# character that might be a shell metacharacter, then use eval to reverse
235+
# that process (while maintaining the separation between arguments), and wrap
236+
# the whole thing up as a single "set" statement.
237+
#
238+
# This will of course break if any of these variables contains a newline or
239+
# an unmatched quote.
240+
#
241+
242+
eval "set -- $(
243+
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
244+
xargs -n1 |
245+
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
246+
tr '\n' ' '
247+
)" '"$@"'
248+
249+
exec "$JAVACMD" "$@"

‎gradlew.bat

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem https://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
17+
@if "%DEBUG%"=="" @echo off
18+
@rem ##########################################################################
19+
@rem
20+
@rem Gradle startup script for Windows
21+
@rem
22+
@rem ##########################################################################
23+
24+
@rem Set local scope for the variables with windows NT shell
25+
if "%OS%"=="Windows_NT" setlocal
26+
27+
set DIRNAME=%~dp0
28+
if "%DIRNAME%"=="" set DIRNAME=.
29+
@rem This is normally unused
30+
set APP_BASE_NAME=%~n0
31+
set APP_HOME=%DIRNAME%
32+
33+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
34+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
35+
36+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
37+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
38+
39+
@rem Find java.exe
40+
if defined JAVA_HOME goto findJavaFromJavaHome
41+
42+
set JAVA_EXE=java.exe
43+
%JAVA_EXE% -version >NUL 2>&1
44+
if %ERRORLEVEL% equ 0 goto execute
45+
46+
echo.
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48+
echo.
49+
echo Please set the JAVA_HOME variable in your environment to match the
50+
echo location of your Java installation.
51+
52+
goto fail
53+
54+
:findJavaFromJavaHome
55+
set JAVA_HOME=%JAVA_HOME:"=%
56+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
57+
58+
if exist "%JAVA_EXE%" goto execute
59+
60+
echo.
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62+
echo.
63+
echo Please set the JAVA_HOME variable in your environment to match the
64+
echo location of your Java installation.
65+
66+
goto fail
67+
68+
:execute
69+
@rem Setup the command line
70+
71+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
72+
73+
74+
@rem Execute Gradle
75+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
76+
77+
:end
78+
@rem End local scope for the variables with windows NT shell
79+
if %ERRORLEVEL% equ 0 goto mainEnd
80+
81+
:fail
82+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83+
rem the _cmd.exe /c_ return code!
84+
set EXIT_CODE=%ERRORLEVEL%
85+
if %EXIT_CODE% equ 0 set EXIT_CODE=1
86+
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
87+
exit /b %EXIT_CODE%
88+
89+
:mainEnd
90+
if "%OS%"=="Windows_NT" endlocal
91+
92+
:omega
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package com.authsignal;
2+
3+
import com.authsignal.models.*;
4+
import com.google.gson.Gson;
5+
import com.nimbusds.jose.JOSEException;
6+
import com.nimbusds.jose.JWSVerifier;
7+
import com.nimbusds.jose.crypto.MACVerifier;
8+
import com.nimbusds.jwt.JWTClaimsSet;
9+
import com.nimbusds.jwt.SignedJWT;
10+
11+
import net.minidev.json.JSONObject;
12+
13+
import java.io.IOException;
14+
import java.net.URI;
15+
import java.net.URISyntaxException;
16+
import java.net.http.HttpClient;
17+
import java.net.http.HttpRequest;
18+
import java.net.http.HttpResponse;
19+
import java.text.ParseException;
20+
import java.util.Base64;
21+
22+
public class AuthsignalClient {
23+
private String _secret;
24+
private String _baseURL;
25+
26+
public AuthsignalClient(String secret, String baseURL) {
27+
this._secret = secret;
28+
this._baseURL = baseURL;
29+
}
30+
31+
public AuthsignalClient(String secret) {
32+
this._secret = secret;
33+
this._baseURL = "https://api.authsignal.com/v1";
34+
}
35+
36+
public UserResponse getUser(UserRequest request) throws URISyntaxException, IOException, InterruptedException {
37+
String path = String.format("/users/%s", request.userId);
38+
39+
HttpResponse<String> response = getRequest(path);
40+
41+
return new Gson().fromJson(response.body(), UserResponse.class);
42+
}
43+
44+
public TrackResponse track(TrackRequest request) throws URISyntaxException, IOException, InterruptedException {
45+
String path = String.format("/users/%s/actions/%s", request.userId, request.action);
46+
47+
TrackRequestBody body = new TrackRequestBody();
48+
49+
body.idempotencyKey = request.idempotencyKey;
50+
body.email = request.email;
51+
body.phoneNumber = request.phoneNumber;
52+
body.username = request.username;
53+
body.redirectUrl = request.redirectUrl;
54+
body.ipAddress = request.ipAddress;
55+
body.userAgent = request.userAgent;
56+
body.deviceId = request.deviceId;
57+
body.redirectToSettings = request.redirectToSettings;
58+
59+
HttpResponse<String> response = postRequest(path, new Gson().toJson(body));
60+
61+
return new Gson().fromJson(response.body(), TrackResponse.class);
62+
}
63+
64+
public ActionResponse getAction(ActionRequest request)
65+
throws URISyntaxException, IOException, InterruptedException {
66+
String path = String.format("/users/%s/actions/%s/%s", request.userId, request.action, request.idempotencyKey);
67+
68+
HttpResponse<String> response = getRequest(path);
69+
70+
return new Gson().fromJson(response.body(), ActionResponse.class);
71+
}
72+
73+
public ValidateChallengeResponse validateChallenge(ValidateChallengeRequest request)
74+
throws URISyntaxException, IOException, InterruptedException, ParseException, JOSEException {
75+
76+
ValidateChallengeResponse response = new ValidateChallengeResponse();
77+
78+
JWSVerifier verifier = new MACVerifier(_secret);
79+
80+
SignedJWT parsedJWT = SignedJWT.parse(request.token);
81+
82+
Boolean isValid = parsedJWT.verify(verifier);
83+
84+
if (!isValid) {
85+
response.success = false;
86+
87+
return response;
88+
}
89+
90+
JWTClaimsSet claims = parsedJWT.getJWTClaimsSet();
91+
92+
String userId = claims.getSubject();
93+
94+
if (request.userId != null && !request.userId.equals(userId)) {
95+
response.success = false;
96+
97+
return response;
98+
}
99+
100+
JSONObject other = claims.getJSONObjectClaim("other");
101+
String action = other.getAsString("actionCode");
102+
String idempotencyKey = other.getAsString("idempotencyKey");
103+
104+
ActionRequest actionRequest = new ActionRequest();
105+
actionRequest.userId = userId;
106+
actionRequest.action = action;
107+
actionRequest.idempotencyKey = idempotencyKey;
108+
109+
ActionResponse actionResponse = getAction(actionRequest);
110+
111+
response.success = actionResponse.state == UserActionState.CHALLENGE_SUCCEEDED;
112+
response.state = actionResponse.state;
113+
response.userId = userId;
114+
115+
return response;
116+
}
117+
118+
public EnrollVerifiedAuthenticatorResponse enrollVerifiedAuthenticator(EnrollVerifiedAuthenticatorRequest request)
119+
throws URISyntaxException, IOException, InterruptedException {
120+
String path = String.format("/users/%s/authenticators", request.userId);
121+
122+
EnrollVerifiedAuthenticatorRequestBody body = new EnrollVerifiedAuthenticatorRequestBody();
123+
124+
body.oobChannel = request.oobChannel;
125+
body.email = request.email;
126+
body.phoneNumber = request.phoneNumber;
127+
body.isDefault = request.isDefault;
128+
129+
HttpResponse<String> response = postRequest(path, new Gson().toJson(body));
130+
131+
return new Gson().fromJson(response.body(), EnrollVerifiedAuthenticatorResponse.class);
132+
}
133+
134+
private HttpResponse<String> getRequest(String path) throws URISyntaxException, IOException, InterruptedException {
135+
HttpClient client = HttpClient.newHttpClient();
136+
137+
HttpRequest request = HttpRequest.newBuilder()
138+
.uri(new URI(_baseURL + path))
139+
.header("Authorization", getBasicAuthHeader())
140+
.GET()
141+
.build();
142+
143+
return client.send(request, HttpResponse.BodyHandlers.ofString());
144+
}
145+
146+
private HttpResponse<String> postRequest(String path, String body)
147+
throws URISyntaxException, IOException, InterruptedException {
148+
HttpClient client = HttpClient.newHttpClient();
149+
150+
HttpRequest request = HttpRequest.newBuilder()
151+
.uri(new URI(_baseURL + path))
152+
.header("Authorization", getBasicAuthHeader())
153+
.header("Content-Type", "application/json")
154+
.POST(HttpRequest.BodyPublishers.ofString(body))
155+
.build();
156+
157+
return client.send(request, HttpResponse.BodyHandlers.ofString());
158+
}
159+
160+
private String getBasicAuthHeader() {
161+
return "Basic " + Base64.getEncoder().encodeToString((this._secret + ":").getBytes());
162+
}
163+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.authsignal.models;
2+
3+
public class ActionRequest {
4+
public String userId;
5+
public String action;
6+
public String idempotencyKey;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.authsignal.models;
2+
3+
public class ActionResponse {
4+
public UserActionState state;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.authsignal.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public enum AuthenticatorType {
6+
@SerializedName("OOB")
7+
OOB,
8+
9+
@SerializedName("OTP")
10+
OTP,
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.authsignal.models;
2+
3+
public class EnrollVerifiedAuthenticatorRequest {
4+
public String userId;
5+
public OobChannel oobChannel;
6+
public String phoneNumber;
7+
public String email;
8+
public Boolean isDefault;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.authsignal.models;
2+
3+
public class EnrollVerifiedAuthenticatorRequestBody {
4+
public OobChannel oobChannel;
5+
public String phoneNumber;
6+
public String email;
7+
public Boolean isDefault;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.authsignal.models;
2+
3+
public class EnrollVerifiedAuthenticatorResponse {
4+
public UserAuthenticator authenticator;
5+
public String[] recoveryCodes;
6+
}
7+
8+
class UserAuthenticator {
9+
public String userId;
10+
public String userAuthenticatorId;
11+
public AuthenticatorType authenticatorType;
12+
public String createdAt;
13+
public String verifiedAt;
14+
public Boolean isDefault;
15+
public Boolean isActive;
16+
public OobChannel oobChannel;
17+
public String phoneNumber;
18+
public String email;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.authsignal.models;
2+
3+
public class JwtPayloadOther {
4+
String tenantId;
5+
String userId;
6+
String email;
7+
String phoneNumber;
8+
String username;
9+
String actionCode;
10+
String idempotencyKey;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.authsignal.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public enum OobChannel {
6+
@SerializedName("SMS")
7+
SMS,
8+
9+
@SerializedName("EMAIL_MAGIC_LINK")
10+
EMAIL_MAGIC_LINK,
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.authsignal.models;
2+
3+
public class TrackRequest {
4+
public String userId;
5+
public String action;
6+
public String idempotencyKey;
7+
public String email;
8+
public String phoneNumber;
9+
public String username;
10+
public String redirectUrl;
11+
public String ipAddress;
12+
public String userAgent;
13+
public String deviceId;
14+
public Boolean redirectToSettings;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.authsignal.models;
2+
3+
public class TrackRequestBody {
4+
public String idempotencyKey;
5+
public String email;
6+
public String phoneNumber;
7+
public String username;
8+
public String redirectUrl;
9+
public String ipAddress;
10+
public String userAgent;
11+
public String deviceId;
12+
public Boolean redirectToSettings;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.authsignal.models;
2+
3+
public class TrackResponse {
4+
public UserActionState state;
5+
public String idempotencyKey;
6+
public String url;
7+
public String token;
8+
public Boolean isEnrolled;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.authsignal.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public enum UserActionState {
6+
@SerializedName("ALLOW")
7+
ALLOW,
8+
9+
@SerializedName("BLOCK")
10+
BLOCK,
11+
12+
@SerializedName("CHALLENGE_REQUIRED")
13+
CHALLENGE_REQUIRED,
14+
15+
@SerializedName("CHALLENGE_SUCCEEDED")
16+
CHALLENGE_SUCCEEDED,
17+
18+
@SerializedName("CHALLENGE_FAILED")
19+
CHALLENGE_FAILED
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.authsignal.models;
2+
3+
public class UserRequest {
4+
public String userId;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.authsignal.models;
2+
3+
public class UserResponse {
4+
public String userId;
5+
public Boolean isEnrolled;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.authsignal.models;
2+
3+
public class ValidateChallengeRequest {
4+
public String token;
5+
public String userId;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.authsignal.models;
2+
3+
public class ValidateChallengeResponse {
4+
public Boolean success;
5+
public UserActionState state;
6+
public String userId;
7+
public String action;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.authsignal;
2+
3+
import org.junit.Test;
4+
5+
import com.authsignal.models.*;
6+
import com.nimbusds.jose.JOSEException;
7+
8+
import static org.junit.Assert.*;
9+
10+
import java.io.IOException;
11+
import java.net.URISyntaxException;
12+
import java.text.ParseException;
13+
14+
public class AuthsignalClientTest {
15+
private String baseURL = "https://dev-api.authsignal.com/v1";
16+
private String secret = "UcPsFXS81O3k3xMv9/XBQsjXRc2otwnZ5qGC6jS2DoW6QwXX5FHi0A==";
17+
private String userId = "5a616356-9a74-4d6d-b3bb-1d6e128f4d6b";
18+
private String action = "test-action";
19+
20+
@Test
21+
public void testSequence()
22+
throws URISyntaxException, IOException, InterruptedException, ParseException, JOSEException {
23+
AuthsignalClient client = new AuthsignalClient(secret, baseURL);
24+
25+
UserRequest userRequest = new UserRequest();
26+
userRequest.userId = userId;
27+
28+
UserResponse userResponse = client.getUser(userRequest);
29+
30+
assertNotNull("user response should exist", userResponse);
31+
32+
TrackRequest trackRequest = new TrackRequest();
33+
trackRequest.userId = userId;
34+
trackRequest.action = action;
35+
36+
TrackResponse trackResponse = client.track(trackRequest);
37+
38+
assertNotNull("track should return token", trackResponse.token);
39+
40+
ValidateChallengeRequest validateChallengeRequest = new ValidateChallengeRequest();
41+
validateChallengeRequest.token = trackResponse.token;
42+
validateChallengeRequest.userId = userId;
43+
44+
ValidateChallengeResponse validateChallengeResponse = client.validateChallenge(validateChallengeRequest);
45+
46+
assertEquals(
47+
"state should be allow",
48+
validateChallengeResponse.state,
49+
UserActionState.ALLOW);
50+
}
51+
}

0 commit comments

Comments
 (0)
Please sign in to comment.