public TokenFetcher()

in genie-client/src/main/java/com/netflix/genie/client/security/oauth2/TokenFetcher.java [70:123]


    public TokenFetcher(
        final String oauthUrl,
        final String clientId,
        final String clientSecret,
        final String grantType,
        final String scope
    ) throws GenieClientException {

        log.debug("Constructor called.");

        if (StringUtils.isBlank(oauthUrl)) {
            throw new IllegalArgumentException("URL cannot be null or empty");
        }

        if (StringUtils.isBlank(clientId)) {
            throw new IllegalArgumentException("Client Id cannot be null or empty");
        }

        if (StringUtils.isBlank(clientSecret)) {
            throw new IllegalArgumentException("Client Secret cannot be null or empty");
        }

        if (StringUtils.isBlank(grantType)) {
            throw new IllegalArgumentException("Grant Type cannot be null or empty");
        }

        if (StringUtils.isBlank(scope)) {
            throw new IllegalArgumentException("Scope cannot be null or empty");
        }

        try {
            final URL url = new URL(oauthUrl);

            // Construct the Base path of the type http[s]://serverhost/ for retrofit to work.
            final String oAuthServerUrl = url.getProtocol() + "://" + url.getHost() + "/";
            final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(oAuthServerUrl)
                .addConverterFactory(JacksonConverterFactory.create())
                .build();

            this.oauthUrl = oauthUrl;

            // Instantiate the token service
            this.tokenService = retrofit.create(TokenService.class);

            // Construct the fields map to send to the IDP url.
            this.credentialParams.put(CLIENT_ID, clientId);
            this.credentialParams.put(CLIENT_SECRET, clientSecret);
            this.credentialParams.put(GRANT_TYPE, grantType);
            this.credentialParams.put(SCOPE, scope);
        } catch (final Exception e) {
            throw new GenieClientException("Could not instantiate Token Service due to exception " + e);
        }
    }