All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.credify.sdk.impl.AuthServiceImpl Maven / Gradle / Ivy

package one.credify.sdk.impl;

import one.credify.sdk.AuthService;
import one.credify.sdk.dto.AccessToken;
import one.credify.sdk.dto.CredifyApiResponse;
import one.credify.sdk.dto.IntrospectTokenData;
import one.credify.sdk.dto.IntrospectTokenRequest;
import one.credify.sdk.restapi.CredifyRestV1;

import java.io.IOException;

public class AuthServiceImpl implements AuthService {
    private final CredifyRestV1 credifyClient;

    public AuthServiceImpl(CredifyRestV1 credifyClient) {
        this.credifyClient = credifyClient;
    }

    @Override
    public String generateAccessToken(String apiKey) throws IOException {
        CredifyApiResponse response = this.credifyClient.generateAccessToken(apiKey).execute().body();
        if (response == null) {
            return null;
        }
        return response.getData().getAccessToken();
    }

    @Override
    public boolean introspectToken(String token, String scope) throws IOException {
        IntrospectTokenRequest req = IntrospectTokenRequest.builder()
                .token(token)
                .scope(scope)
                .build();
        CredifyApiResponse response = this.credifyClient.introspectToken(req).execute().body();
        return response != null && response.getData().isActive();
    }

    @Override
    public IntrospectTokenData introspectTokenReturnResult(String token) throws IOException {
        IntrospectTokenRequest req = IntrospectTokenRequest.builder()
                .token(token)
                .build();
        CredifyApiResponse response = this.credifyClient.introspectToken(req).execute().body();
        if (response == null) {
            return null;
        }
        return response.getData();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy