Skip to content

Commit

Permalink
1: Create XING Connector
Browse files Browse the repository at this point in the history
  • Loading branch information
keilw committed Jan 6, 2016
1 parent e3a2e5f commit b1e9c28
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
10 changes: 8 additions & 2 deletions agorava-core-api/src/main/java/org/agorava/AgoravaConstants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Agorava
* Copyright 2016 Agorava
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
* This interface contains OAuth and other Agorava constants
*
* @author Antoine Sabot-Durand
* @author Werner Keil
*/
public interface AgoravaConstants {
/**
Expand Down Expand Up @@ -130,7 +131,12 @@ public interface AgoravaConstants {
* Return code field name in OAuth request
*/
String CODE = "code";


/**
* Return grant type in OAuth request
*/
String GRANT_TYPE = "grant_type";

/**
* default OAuth Callback relative url to send user when returning from OAuth service. It's used in {@link org.agorava
* .api.oauth.application.SimpleOAuthAppSettingsBuilder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.agorava.api.oauth;

import org.agorava.api.oauth.application.OAuthAppSettings;
import org.agorava.api.rest.Response;
import org.agorava.api.rest.RestService;
import org.agorava.api.rest.Verb;
Expand Down Expand Up @@ -204,5 +205,8 @@ public interface OAuthService extends RestService {
*/
JsonMapperService getJsonMapper();


/**
* @return configuration settings needed to access an OAuth 1.0a and 2.0 service tier
*/
OAuthAppSettings getConfig();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Agorava
* Copyright 2016 Agorava
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@
import org.agorava.api.rest.Response;
import org.agorava.spi.ProviderConfigOauth10a;
import org.agorava.utils.MapUtils;

import static org.agorava.api.oauth.OAuth.OAuthVersion.ONE;

import java.util.Map;
Expand All @@ -40,8 +41,10 @@
*
* @author Antoine Sabot-Durand
* @author Pablo Fernandez
* @author Werner Keil
*/

@SuppressWarnings("serial")
@Generic
@OAuth(ONE)
public class OAuth10aServiceImpl extends OAuthServiceBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Token getAccessToken(Token requestToken, Verifier verifier) {
request.addBodyParameter(AgoravaConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(AgoravaConstants.CODE, verifier.getValue());
request.addBodyParameter(AgoravaConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
request.addBodyParameter(AgoravaConstants.GRANT_TYPE, "authorization_code");
if (config.hasScope())
request.addBodyParameter(AgoravaConstants.SCOPE, config.getScope());
Response response = request.send(); //todo:should check return code and launch ResponseException if it's not 200
Expand All @@ -64,4 +64,9 @@ public Token getAccessToken(Token requestToken, Verifier verifier) {
public OAuth.OAuthVersion getVersion() {
return TWO_FINAL;
}

@Override
public OAuthAppSettings getConfig() {
return config;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 Agorava
* Copyright 2016 Agorava
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,16 +28,17 @@
import org.agorava.api.rest.Response;
import org.agorava.rest.OAuthRequestImpl;
import org.agorava.spi.ProviderConfigOauth20;

import static org.agorava.api.oauth.OAuth.OAuthVersion.TWO_DRAFT_11;

@SuppressWarnings("serial")
@Generic
@OAuth(TWO_DRAFT_11)
public class OAuth20ServiceImpl extends OAuthServiceBase {

@InjectWithQualifier
ProviderConfigOauth20 api;


/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -76,7 +77,6 @@ public void signRequest(Token accessToken, OAuthRequest request) {
request.addQuerystringParameter(AgoravaConstants.ACCESS_TOKEN, accessToken.getToken());
}


@Override
public String getVerifierParamName() {
return AgoravaConstants.CODE;
Expand All @@ -86,6 +86,4 @@ public String getVerifierParamName() {
public String getAuthorizationUrl() {
return api.getAuthorizationUrl(getTunedOAuthAppSettings());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public Response sendSignedXmlRequest(Verb verb, String uri, String payload) {
@Override
public OAuthSession getSession() {
return OAuthLifeCycleService.resolveSessionForQualifier(config.getQualifier());

}

@Override
Expand Down Expand Up @@ -189,13 +188,17 @@ public <T> T get(String uri, Class<T> clazz, boolean signed) {
else
resp = requestFactory(GET, uri).send(); //todo:should check return code and launch
// ResponseException if it's not 200
LOGGER.warning("R: " + resp.toString());
return getJsonMapper().mapToObject(resp, clazz);
}

@Override
public <T> T get(String uri, Class<T> clazz, Object... urlParams) {
String url = MessageFormat.format(uri, urlParams);
return getJsonMapper().mapToObject(sendSignedRequest(GET, url), clazz);
public <T> T get(String uri, Class<T> clazz, Object... urlParams) {
final String url = MessageFormat.format(uri, urlParams);
LOGGER.warning("U: " + url);
Response resp = sendSignedRequest(GET, url);
LOGGER.warning("R: " + resp.toString());
return getJsonMapper().mapToObject(resp, clazz);
}

@Override
Expand Down Expand Up @@ -241,5 +244,8 @@ protected OAuthAppSettings getTunedOAuthAppSettings() {
AppSettingsTuner tuner = BeanResolver.getInstance().resolve(AppSettingsTuner.class, true);
return tuner == null ? config : tuner.tune(config);
}


public OAuthAppSettings getConfig() {
return config;
}
}

0 comments on commit b1e9c28

Please sign in to comment.