Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

Error: unauthorized_client : Invalid redirect_uri

Started by Jason Raikes -   in API Authentication

Hi,

I am using some code that works in my live environment and I am trying to use it in my development environment but get the error 'Error: unauthorized_client : Invalid redirect_uri'.

I have changed the redirect to the external ip address of my internet router and set up the port forwarding on the router to forward https requests to my development environment, I have also added the same ip address and the full path tto the redirect resource to the app config on the Xero developer site.

My code is as follows:

private static final long serialVersionUID = 1L;
final String clientId = "XXXXXXXXXXXXXXXXXXX";
final String clientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
final String redirectURI = "https://XXX.XXX.XX.XXX";
final String TOKEN_SERVER_URL = "https://identity.xero.com/connect/token";
final String AUTHORIZATION_SERVER_URL = "https://login.xero.com/identity/connect/authorize";
final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
final JsonFactory JSON_FACTORY = new JacksonFactory();


public void xero_oauth2(String call, HttpServletResponse response)
{
try
{
ArrayList<String> scopeList = new ArrayList<String>();
scopeList.add("openid");
scopeList.add("offline_access");
scopeList.add("accounting.transactions");
scopeList.add("accounting.attachments");
scopeList.add("accounting.contacts");
scopeList.add("accounting.settings");
scopeList.add("accounting.journals.read");

DataStoreFactory DATA_STORE_FACTORY = new MemoryDataStoreFactory();
AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),
HTTP_TRANSPORT,
JSON_FACTORY,
new GenericUrl(TOKEN_SERVER_URL),
new ClientParametersAuthentication(clientId, clientSecret), clientId, AUTHORIZATION_SERVER_URL)
.setScopes(scopeList)
.setDataStoreFactory(DATA_STORE_FACTORY)
.build();


String url = flow.newAuthorizationUrl()
.setClientId(clientId)
.setScopes(scopeList)
.setState(call)
.setRedirectUri(redirectURI + ":8443/dbWeb/AjaxXero").build();

response.sendRedirect(url);
}
catch(Exception e)
{
e.printStackTrace();
}
}

Any clues would be useful.

Regards,

Jason