vertx.effect.httpclient.oauth.AuthorizationCodeModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-effect Show documentation
Show all versions of vertx-effect Show documentation
When actors meet Functional Programming
package vertx.effect.httpclient.oauth;
import io.vavr.Tuple2;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpClientOptions;
import jsonvalues.JsObj;
import vertx.effect.core.OauthModule;
import vertx.effect.Val;
import vertx.effect.λ;
import vertx.effect.httpclient.HttpClientModule;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
public class AuthorizationCodeModule extends OauthModule {
protected String refreshToken;
protected BiFunction> authenticateReq;
protected λ> readTokensAfterAuthentication;
AuthorizationCodeModule(final HttpClientOptions options,
final String address,
final Function>> accessTokenReq,
final String authorizationHeaderName,
final Function authorizationHeaderValue,
final λ readNewAccessTokenAfterRefresh,
final Predicate refreshTokenPredicate,
final Predicate retryAccessTokenReqPredicate,
final Predicate retryReqPredicate,
final int accessTokenReqAttempts,
final int reqAttempts,
final String refreshToken
) {
super(options,
address,
authorizationHeaderName,
authorizationHeaderValue,
readNewAccessTokenAfterRefresh,
refreshTokenPredicate,
retryAccessTokenReqPredicate,
retryReqPredicate,
accessTokenReqAttempts,
reqAttempts
);
this.accessTokenReq = accessTokenReq.apply(refreshToken);
this.refreshToken = refreshToken;
}
AuthorizationCodeModule(final HttpClientOptions options,
final String address,
final BiFunction> authenticateReq,
final Function>> accessTokenReq,
final λ> readTokensAfterAuthentication,
final String authorizationHeaderName,
final Function authorizationHeaderValue,
final λ readNewAccessTokenAfterRefresh,
final Predicate refreshTokenPredicate,
final Predicate retryAccessTokenReqPredicate,
final Predicate retryReqPredicate,
final int accessTokenReqAttempts,
final int reqAttempts
) {
super(options,
address,
authorizationHeaderName,
authorizationHeaderValue,
readNewAccessTokenAfterRefresh,
refreshTokenPredicate,
retryAccessTokenReqPredicate,
retryReqPredicate,
accessTokenReqAttempts,
reqAttempts
);
this.accessTokenReq = accessTokenReq.apply(refreshToken);
this.authenticateReq = authenticateReq;
this.readTokensAfterAuthentication = readTokensAfterAuthentication;
}
public Val> authenticate(JsObj input) {
return authenticateReq.apply(this,
input
)
.flatMap(readTokensAfterAuthentication)
.onSuccess(tokens -> {
this.accessToken = tokens._1;
this.refreshToken = tokens._2;
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy