use of com.github.scribejava.core.model.OAuth2Authorization in project scribejava by scribejava.
the class OAuth20ServiceTest method testOAuthExtractAuthorization.
@Test
public void testOAuthExtractAuthorization() {
final OAuth20Service service = new ServiceBuilder().apiKey("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());
}
use of com.github.scribejava.core.model.OAuth2Authorization in project scribejava by scribejava.
the class OAuth20Service method extractAuthorization.
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) {
switch(keyValue[0]) {
case "code":
authorization.setCode(keyValue[1]);
break;
case "state":
authorization.setState(keyValue[1]);
break;
//just ignore any other param;
default:
}
}
}
return authorization;
}
Aggregations