Search in sources :

Example 1 with QueryParameter

use of com.okta.authn.sdk.http.QueryParameter in project okta-auth-java by okta.

the class ReadmeSnippets method headersAndQuery.

private void headersAndQuery() {
    List<Header> headers = new ArrayList<>();
    // set any header
    headers.add(new Header("aHeaderName", "aValue"));
    // X-Forwarded-For
    headers.add(Header.xForwardedFor("10.10.0.1"));
    // X-Device-Fingerprint
    headers.add(Header.xDeviceFingerprint("your-finger-print"));
    List<QueryParameter> queryParameters = new ArrayList<>();
    // set query param
    queryParameters.add(new QueryParameter("aQueryParam", "aValue"));
    RequestContext requestContext = new RequestContext(headers, queryParameters);
}
Also used : QueryParameter(com.okta.authn.sdk.http.QueryParameter) Header(com.okta.authn.sdk.http.Header) ArrayList(java.util.ArrayList) RequestContext(com.okta.authn.sdk.http.RequestContext)

Example 2 with QueryParameter

use of com.okta.authn.sdk.http.QueryParameter in project okta-auth-java by okta.

the class DefaultAuthenticationClient method doPost.

private AuthenticationResponse doPost(String href, Resource request, AuthenticationStateHandler authenticationStateHandler, RequestContext requestContext) throws AuthenticationException {
    try {
        Map<String, Object> query = null;
        Map<String, List<String>> headers = null;
        if (requestContext != null) {
            query = requestContext.getQueryParams().stream().collect(Collectors.toMap(QueryParameter::getKey, QueryParameter::getValue));
            headers = requestContext.getHeaders().stream().collect(Collectors.toMap(Header::getKey, Header::getValue, (a, b) -> Stream.concat(a.stream(), b.stream()).collect(Collectors.toList())));
        }
        AuthenticationResponse authenticationResponse = getDataStore().create(href, request, null, AuthenticationResponse.class, query, headers);
        if (authenticationStateHandler != null) {
            handleResult(authenticationResponse, authenticationStateHandler);
        }
        return authenticationResponse;
    } catch (ResourceException e) {
        translateException(e);
        // above method should always throw
        throw e;
    }
}
Also used : QueryParameter(com.okta.authn.sdk.http.QueryParameter) Header(com.okta.authn.sdk.http.Header) List(java.util.List) ResourceException(com.okta.sdk.resource.ResourceException) AuthenticationResponse(com.okta.authn.sdk.resource.AuthenticationResponse)

Aggregations

Header (com.okta.authn.sdk.http.Header)2 QueryParameter (com.okta.authn.sdk.http.QueryParameter)2 RequestContext (com.okta.authn.sdk.http.RequestContext)1 AuthenticationResponse (com.okta.authn.sdk.resource.AuthenticationResponse)1 ResourceException (com.okta.sdk.resource.ResourceException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1