use of org.apache.oltu.oauth2.client.OAuthClient in project BIMserver by opensourceBIM.
the class OAuthServiceImpl method registerRemoteApplication.
public SOAuthServer registerRemoteApplication(String redirectUrl, String name, String description) throws UserException {
try {
OAuthClientRequest request = OAuthClientRegistrationRequest.location(getBimServer().getServerSettingsCache().getServerSettings().getSiteAddress() + "/oauth/register/", OAuthRegistration.Type.PUSH).setName(name).setUrl(redirectUrl).setDescription(description).setRedirectURL(redirectUrl).buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
SOAuthServer server = new SOAuthServer();
server.setClientId(response.getClientId());
server.setClientSecret(response.getClientSecret());
return server;
} catch (Exception e) {
throw new UserException(e);
}
}
use of org.apache.oltu.oauth2.client.OAuthClient in project BIMserver by opensourceBIM.
the class SendUrl method main.
public static void main(String[] args) {
try {
OAuthClientRequest request = OAuthClientRegistrationRequest.location("https://thisisanexperimentalserver.com/oauth/register/", OAuthRegistration.Type.PUSH).setName("Zapier").setUrl("https://zapier.com/dashboard/auth/oauth/return/App56192API").setDescription("App Description").setRedirectURL("https://zapier.com/dashboard/auth/oauth/return/App56192API").buildJSONMessage();
OAuthRegistrationClient oauthclient = new OAuthRegistrationClient(new org.bimserver.webservices.impl.URLConnectionClient());
OAuthClientRegistrationResponse response = oauthclient.clientInfo(request);
System.out.println(response.getClientId());
System.out.println(response.getClientSecret());
} catch (OAuthSystemException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (OAuthProblemException e) {
e.printStackTrace();
}
}
use of org.apache.oltu.oauth2.client.OAuthClient in project components by Talend.
the class Oauth2ImplicitClient method getToken.
public <T extends OAuthAccessTokenResponse> T getToken(Class<T> tokenResponseClass) {
try {
TokenRequestBuilder builder = //
OAuthClientRequest.tokenLocation(//
tokenLocation.toString()).setGrantType(//
grantType).setClientId(//
clientID).setClientSecret(clientSecret);
if (GrantType.AUTHORIZATION_CODE == grantType) {
builder = //
builder.setRedirectURI(callbackURL.toString()).setCode(getAuthorizationCode());
} else if (GrantType.REFRESH_TOKEN == grantType) {
builder = builder.setRefreshToken(refreshToken);
}
OAuthClientRequest request = builder.buildQueryMessage();
OAuthClient oauthClient = new OAuthClient(new URLConnectionClient());
return oauthClient.accessToken(request, tokenResponseClass);
} catch (OAuthSystemException e) {
throw new RuntimeException(e);
} catch (OAuthProblemException e) {
throw new RuntimeException(e);
}
}
use of org.apache.oltu.oauth2.client.OAuthClient in project irida by phac-nml.
the class OltuAuthorizationController method getToken.
/**
* Receive the OAuth2 authorization code and request an OAuth2 token
*
* @param request
* The incoming request
* @param response
* The response to redirect
* @param apiId
* the Long ID of the API we're requesting from
* @param redirect
* The URL location to redirect to after completion
* @return A ModelAndView redirecting back to the resource that was
* requested
* @throws IOException
* @throws OAuthSystemException
* @throws OAuthProblemException
* @throws URISyntaxException
*/
@RequestMapping("/token")
public ModelAndView getToken(HttpServletRequest request, HttpServletResponse response, @RequestParam("redirect") String redirect) throws IOException, OAuthSystemException, OAuthProblemException, URISyntaxException {
// Get the OAuth2 auth code
OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
String code = oar.getCode();
logger.debug("got code " + code);
// Read the RemoteAPI from the RemoteAPIService and get the base URI
// Build the token location for this service
URI serviceTokenLocation = UriBuilder.fromUri(serviceURI).path("oauth").path("token").build();
logger.debug("token loc " + serviceTokenLocation);
// Build the redirect URI to request a token from
String tokenRedirect = buildRedirectURI(redirect);
// Create the token request form the given auth code
OAuthClientRequest tokenRequest = OAuthClientRequest.tokenLocation(serviceTokenLocation.toString()).setClientId(clientId).setClientSecret(clientSecret).setRedirectURI(tokenRedirect).setCode(code).setGrantType(GrantType.AUTHORIZATION_CODE).buildBodyMessage();
// execute the request
OAuthClient client = new OAuthClient(new URLConnectionClient());
// read the response for the access token
OAuthJSONAccessTokenResponse accessTokenResponse = client.accessToken(tokenRequest, OAuthJSONAccessTokenResponse.class);
String accessToken = accessTokenResponse.getAccessToken();
// check the token expiry
Long expiresIn = accessTokenResponse.getExpiresIn();
logger.debug("Token expires in " + expiresIn);
// adding the token to the response page. This is just a demo to show
// how to get an oauth token. NEVER DO THIS!!!
redirect = redirect + "?token=" + accessToken;
// redirect the response back to the requested resource
return new ModelAndView(new RedirectView(redirect));
}
use of org.apache.oltu.oauth2.client.OAuthClient in project irida by phac-nml.
the class RemoteAPITokenServiceImplTest method setUp.
@Before
public void setUp() {
tokenRepository = mock(RemoteApiTokenRepository.class);
userRepo = mock(UserRepository.class);
oauthClient = mock(OAuthClient.class);
service = new RemoteAPITokenServiceImpl(tokenRepository, userRepo, oauthClient);
user = new User("tom", "an@email.com", "password1", "tom", "matthews", "123456789");
remoteAPI = new RemoteAPI("apiname", "http://nowhere", "a test api", "clientId", "clientSecret");
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(user, null));
remoteAPIToken = new RemoteAPIToken("token", remoteAPI, new Date());
}
Aggregations