final Integer index = this.cache.getOAuth2AccessorIndex(gadgetUri, serviceName, user, scope);
OAuth2Accessor ret = this.cache.getOAuth2Accessor(index);
if ((ret == null) || (!ret.isValid())) {
final OAuth2Client client = this.getClient(gadgetUri, serviceName);
if (client != null) {
final OAuth2Token accessToken = this.getToken(gadgetUri, serviceName, user, scope,
OAuth2Token.Type.ACCESS);
final OAuth2Token refreshToken = this.getToken(gadgetUri, serviceName, user, scope,
OAuth2Token.Type.REFRESH);
final BasicOAuth2Accessor newAccessor = new BasicOAuth2Accessor(gadgetUri, serviceName,
user, scope, client.isAllowModuleOverride(), this, this.globalRedirectUri);
newAccessor.setAccessToken(accessToken);
newAccessor.setAuthorizationUrl(client.getAuthorizationUrl());
newAccessor.setClientAuthenticationType(client.getClientAuthenticationType());
newAccessor.setAuthorizationHeader(client.isAuthorizationHeader());
newAccessor.setUrlParameter(client.isUrlParameter());
newAccessor.setClientId(client.getClientId());
newAccessor.setClientSecret(client.getClientSecret());
newAccessor.setGrantType(client.getGrantType());
newAccessor.setRedirectUri(client.getRedirectUri());
newAccessor.setRefreshToken(refreshToken);
newAccessor.setTokenUrl(client.getTokenUrl());
newAccessor.setType(client.getType());
ret = newAccessor;
this.storeOAuth2Accessor(ret);
}
}