OAuth2TokenExtractor { void extractAccessTokenForImplicitGrantFlow(final OAuth2Parameters parameters) throws OAuthSystemException, URISyntaxException, MalformedURLException { final UserBrowserFacade browserFacade = getBrowserFacade(); addBrowserInteractionHandler(browserFacade, parameters); addExternalListeners(browserFacade); browserFacade.addBrowserListener(new BrowserListenerAdapter() { @Override public void locationChanged(String newLocation) { String accessToken = extractAuthorizationCodeFromForm(extractFormData(newLocation), ACCESS_TOKEN); if (!StringUtils.isNullOrEmpty(accessToken)) { parameters.setAccessTokenInProfile(accessToken); parameters.setRefreshTokenInProfile(null); parameters.setAccessTokenExpirationTimeInProfile(0); parameters.setAccessTokenIssuedTimeInProfile(TimeUtils.getCurrentTimeInSeconds()); browserFacade.close(); } } @Override public void browserClosed() { super.browserClosed(); if (!parameters.isAccessTokenRetrivedFromServer()) { setRetrievedCanceledStatus(parameters); } } }); browserFacade.open(new URI(createAuthorizationURL(parameters, TOKEN)).toURL()); parameters.waitingForAuthorization(); }  void extractAccessToken(final OAuth2Parameters parameters); OAuthClientRequest getClientRequestForROPC(final OAuth2Parameters parameters); void extractAccessTokenForClientCredentialsGrant(final OAuth2Parameters parameters); OAuthClientRequest getClientRequestForClientCredentialsGrant(final OAuth2Parameters parameters); void addBrowserListener(BrowserListener listener); static final String CODE; static final String TITLE; static final String TOKEN; static final String ACCESS_TOKEN; }
@Test public void getsAccessTokenFromURLFragmentForImplicitGrantFlow() throws OAuthSystemException, MalformedURLException, URISyntaxException { oAuth2TokenExtractor.extractAccessTokenForImplicitGrantFlow(parameters); assertThat(profile.getAccessToken(), is(ACCESS_TOKEN)); }