Skip to content

Commit

Permalink
refactor: PR comment: use shared ApplicationAuthManager for Voice & V…
Browse files Browse the repository at this point in the history
…erification
  • Loading branch information
JPPortier committed Dec 19, 2023
1 parent b7876ec commit 55bb4a4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class VerificationApplicationAuthManager implements AuthManager {
public class ApplicationAuthManager implements AuthManager {

private static final String AUTH_KEYWORD = "Application";
private static final String XTIMESTAMP_HEADER = "x-timestamp";
private final String key;
private final byte[] secret;

public VerificationApplicationAuthManager(String key, String base64Secret) {
public ApplicationAuthManager(String key, String base64Secret) {
this.key = key;
this.secret = Base64.getDecoder().decode(base64Secret);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sinch.sdk.domains.verification.adapters;

import com.sinch.sdk.auth.adapters.ApplicationAuthManager;
import com.sinch.sdk.auth.adapters.BasicAuthManager;
import com.sinch.sdk.auth.adapters.VerificationApplicationAuthManager;
import com.sinch.sdk.core.exceptions.ApiAuthException;
import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
Expand Down Expand Up @@ -46,7 +46,7 @@ public VerificationService(Configuration configuration, HttpClient httpClient) {
private void setApplicationCredentials(String key, String secret) {

AuthManager basicAuthManager = new BasicAuthManager(key, secret);
AuthManager applicationAuthManager = new VerificationApplicationAuthManager(key, secret);
AuthManager applicationAuthManager = new ApplicationAuthManager(key, secret);

boolean useApplicationAuth = true;
// to handle request from client we can only have "Basic" keyword behind the auth managers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sinch.sdk.domains.voice.adapters;

import com.sinch.sdk.auth.adapters.VoiceApplicationAuthManager;
import com.sinch.sdk.auth.adapters.ApplicationAuthManager;
import com.sinch.sdk.core.exceptions.ApiAuthException;
import com.sinch.sdk.core.http.AuthManager;
import com.sinch.sdk.core.http.HttpClient;
Expand Down Expand Up @@ -36,7 +36,7 @@ public VoiceService(Configuration configuration, HttpClient httpClient) {

private void setApplicationCredentials(String key, String secret) {

AuthManager applicationAuthManager = new VoiceApplicationAuthManager(key, secret);
AuthManager applicationAuthManager = new ApplicationAuthManager(key, secret);

clientAuthManagers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
clientAuthManagers.put(SECURITY_SCHEME_KEYWORD, applicationAuthManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import org.mockito.MockedStatic;
import org.mockito.Mockito;

class VerificationApplicationAuthManagerTest {
class ApplicationAuthManagerTest {

static final String KEY = "my-key-id";
static final String SECRET =
Base64.getEncoder().encodeToString("my-key-secret".getBytes(StandardCharsets.UTF_8));

AuthManager authManager = new VerificationApplicationAuthManager(KEY, SECRET);
AuthManager authManager = new ApplicationAuthManager(KEY, SECRET);

@Test
void getSchema() {
Expand Down

0 comments on commit 55bb4a4

Please sign in to comment.