22
33import static com .yoti .api .client .spi .remote .call .YotiConstants .DEFAULT_YOTI_HOST ;
44import static com .yoti .api .client .spi .remote .call .YotiConstants .PROPERTY_YOTI_DOCS_URL ;
5- import static com .yoti .api .client .spi .remote .util .Validation .notNull ;
6- import static com .yoti .api .client .spi .remote .util .Validation .notNullOrEmpty ;
5+ import static com .yoti .validation .Validation .notNullOrEmpty ;
76
87import java .io .IOException ;
98import java .net .URISyntaxException ;
1918import com .yoti .api .client .spi .remote .call .ResourceException ;
2019import com .yoti .api .client .spi .remote .call .YotiHttpRequest ;
2120import com .yoti .api .client .spi .remote .call .YotiHttpRequestBuilderFactory ;
21+ import com .yoti .api .client .spi .remote .call .factory .AuthStrategy ;
22+ import com .yoti .api .client .spi .remote .call .factory .AuthTokenStrategy ;
2223import com .yoti .api .client .spi .remote .call .factory .DocsSignedRequestStrategy ;
2324
2425import com .fasterxml .jackson .databind .ObjectMapper ;
@@ -34,10 +35,10 @@ public class DocScanSandboxClient {
3435 private final ObjectMapper mapper ;
3536 private final YotiHttpRequestBuilderFactory yotiHttpRequestBuilderFactory ;
3637 private final String sdkId ;
37- private final DocsSignedRequestStrategy authStrategy ;
38+ private final AuthStrategy authStrategy ;
3839
3940 private DocScanSandboxClient (String sdkId ,
40- DocsSignedRequestStrategy authStrategy ,
41+ AuthStrategy authStrategy ,
4142 ObjectMapper mapper ,
4243 YotiHttpRequestBuilderFactory yotiHttpRequestBuilderFactory ) {
4344 this .sdkId = sdkId ;
@@ -107,10 +108,15 @@ public static class Builder {
107108
108109 private static final Logger LOGGER = LoggerFactory .getLogger (Builder .class );
109110
111+ private String authenticationToken ;
110112 private String sdkId ;
111113 private KeyPair keyPair ;
112114
113- private Builder () {
115+ private Builder () {}
116+
117+ public Builder withAuthenticationToken (String authenticationToken ) {
118+ this .authenticationToken = authenticationToken ;
119+ return this ;
114120 }
115121
116122 public Builder withSdkId (String sdkId ) {
@@ -130,10 +136,28 @@ public Builder withKeyPair(KeyPairSource keyPairSource) {
130136
131137 public DocScanSandboxClient build () {
132138 notNullOrEmpty (sdkId , "sdkId" );
133- notNull (keyPair , "keyPair" );
134139
135- return new DocScanSandboxClient (sdkId , new DocsSignedRequestStrategy (keyPair , sdkId ), new ObjectMapper (), new YotiHttpRequestBuilderFactory ());
140+ if (authenticationToken == null ) {
141+ validateForSignedRequest ();
142+ return new DocScanSandboxClient (sdkId , new DocsSignedRequestStrategy (keyPair , sdkId ), new ObjectMapper (), new YotiHttpRequestBuilderFactory ());
143+ } else {
144+ validateAuthToken ();
145+ return new DocScanSandboxClient (sdkId , new AuthTokenStrategy (authenticationToken ), new ObjectMapper (), new YotiHttpRequestBuilderFactory ());
146+ }
147+ }
148+
149+ private void validateForSignedRequest () {
150+ if (sdkId == null || sdkId .isEmpty () || keyPair == null ) {
151+ throw new IllegalStateException ("An sdkId and KeyPairSource must be provided when not using an authentication token" );
152+ }
136153 }
154+
155+ private void validateAuthToken () {
156+ if (keyPair != null ) {
157+ throw new IllegalStateException ("Must not supply KeyPairSource when using an authentication token" );
158+ }
159+ }
160+
137161 }
138162
139163}
0 commit comments