public OAuth2Authorization extractAuthorization(String redirectLocation) {
        final OAuth2Authorization authorization = new OAuth2Authorization();
        int end = redirectLocation.indexOf('#');
        if (end == -1) {
            end = redirectLocation.length();
        }
        for (String param : redirectLocation.substring(redirectLocation.indexOf('?') + 1, end).split("&")) {
            final String[] keyValue = param.split("=");
            if (keyValue.length == 2) {
                try {
                    switch (keyValue[0]) {
                        case "code":
                            authorization.setCode(URLDecoder.decode(keyValue[1], "UTF-8"));
                            break;
                        case "state":
                            authorization.setState(URLDecoder.decode(keyValue[1], "UTF-8"));
                            break;
                        default: //just ignore any other param;
                    }
                } catch (UnsupportedEncodingException ueE) {
                    throw new IllegalStateException("jvm without UTF-8, really?", ueE);
                }
            }
        }
        return authorization;
    }
@Test
    public void testOAuthExtractAuthorization() {
        final OAuth20Service service = new ServiceBuilder("your_api_key")
                .apiSecret("your_api_secret")
                .build(new OAuth20ApiUnit());

        OAuth2Authorization authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB&state=xyz");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals("xyz", authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?state=xyz&code=SplxlOB");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals("xyz", authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?key=value&state=xyz&code=SplxlOB");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals("xyz", authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?state=xyz&code=SplxlOB&key=value&");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals("xyz", authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB&state=");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals(null, authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?code=SplxlOB");
        assertEquals("SplxlOB", authorization.getCode());
        assertEquals(null, authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?code=");
        assertEquals(null, authorization.getCode());
        assertEquals(null, authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?code");
        assertEquals(null, authorization.getCode());
        assertEquals(null, authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb?");
        assertEquals(null, authorization.getCode());
        assertEquals(null, authorization.getState());

        authorization = service.extractAuthorization("https://cl.ex.com/cb");
        assertEquals(null, authorization.getCode());
        assertEquals(null, authorization.getState());
    }