# Send custom value as query param in social media login and get value in first broker login flow. embedded keycloak with spring boot

**URL:** <https://forum.keycloak.org/t/send-custom-value-as-query-param-in-social-media-login-and-get-value-in-first-broker-login-flow-embedded-keycloak-with-spring-boot/16445>\
**Category:** Miscellanaeous\
**Created:** [July 14, 2022, 4:38am UTC](https://forum.keycloak.org/t/send-custom-value-as-query-param-in-social-media-login-and-get-value-in-first-broker-login-flow-embedded-keycloak-with-spring-boot/16445 "2022-07-14T04:38:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakshanamal](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/lakshanamal/32/6177_2.png) [@lakshanamal](https://forum.keycloak.org/u/lakshanamal)\
**Post date:** [July 14, 2022, 4:38am UTC](https://forum.keycloak.org/t/send-custom-value-as-query-param-in-social-media-login-and-get-value-in-first-broker-login-flow-embedded-keycloak-with-spring-boot/16445/1 "2022-07-14T04:38:06Z")

</div>

**Business Requirement:**" In our software product, we can create organizations, organization admin can send the invitation to the non-registered user to join the organization using their email, After the invitation is received non-registered can click the invitation and redirect to our register page with the invitation token (invitation token include email, invited organization id, and some metadata). Then non-registered users as two options.

1. Normal register flow – we handled, after registering, using token invitation details, the user automatically assigned to the invited organization.
2. Sign-up with social media – not handled "

I try to attach the invitation token as a query param to the google endpoint

[https://xxxxx/com/xventure/auth/realms/Xventure/broker/google/login?client\_id=xapi-dev&tab\_id=6mkiZyMScaE&session\_code=U90AHLxSsMpw8jAbLJgx-u9KwkYbn-8kwAJq0O-scyc&](https://xxxxx/com/xventure/auth/realms/Xventure/broker/google/login?client_id=xapi-dev&tab_id=6mkiZyMScaE&session_code=U90AHLxSsMpw8jAbLJgx-u9KwkYbn-8kwAJq0O-scyc&) **token=xxxxxxxxxxx**

and it captures using a filter

```auto
else if (pathMatcher.match("/**/google/login", pathInfo)) {
        String token = StringUtils.EMPTY;
        Map<String, String[]> parameterMap = wrappedRequest.getParameterMap();
        if (parameterMap.containsKey("token")) {
            token = parameterMap.get("token")[0];
        }
        requestAttributes.setAttribute("token", token, RequestAttributes.SCOPE_REQUEST);
    }

```

then override the GoogleIdentityProvider and set the token to the state variable as postfix

```auto
 protected UriBuilder createAuthorizationUrl(AuthenticationRequest request) {
    UriBuilder url = super.createAuthorizationUrl(request);
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        String token = (String) requestAttributes.getAttribute("token", RequestAttributes.SCOPE_REQUEST);
        if(token != null){
            url.replaceQueryParam("state", request.getState().getEncoded()+"."+token);
        }
    }
    return url;
}

```

after I can capture the token from state.

```auto
else if (pathMatcher.match("/**/google/endpoint", pathInfo)) {
        if (request.getParameterMap().containsKey("state")) {
            String value = request.getParameterMap().get("state")[0];
            String token= Strings.EMPTY;
            Pattern DOT = Pattern.compile("\\.");
            String[] decoded = DOT.split(value, 4);
            token = decoded.length > 3 ? decoded[3] : null;

            requestAttributes.setAttribute("token", token, RequestAttributes.SCOPE_REQUEST);
            FilterRequest filteredRequest = new FilterRequest(request);
            filterChain.doFilter(filteredRequest, response);
        }
    } 

```

but I couldn’t it send to the first-broker-login flow. I tried some class override but not working. I don’t know what is the right class need to override. can you suggest any solution?

Or Can you suggest any solution for the archive this business requirement?
