we using https://github.com/clover/android-exa... to get auth token via oauth in android but we are unable to get token we did all steps provided in example we are able to login in clover but not getting access token .
i am passing "redirect_uri=http://localhost"
as it is
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_webview);
// The URL that will fetch the Access Token, Merchant ID, and Employee ID
String url = "https://clover.com/oauth/authorize" +
"?client_id=" + "myappid" +
"&response_type=token" +
"&redirect_uri=http://localhost";
// Creates the WebView
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// Parses the fetched URL
String accessTokenFragment = "#access_token=";
String merchantIdFragment = "&merchant_id=";
String employeeIdFragment = "&employee_id=";
int accessTokenStart = url.indexOf(accessTokenFragment);
int merchantIdStart = url.indexOf(merchantIdFragment);
int employeeIdStart = url.indexOf(employeeIdFragment);
if (accessTokenStart > -1) {
String accessToken = url.substring(accessTokenStart + accessTokenFragment.length(), merchantIdStart);
String merchantId = url.substring(merchantIdStart + merchantIdFragment.length(), employeeIdStart);
String employeeId = url.substring(employeeIdStart + employeeIdFragment.length(), url.length());
// Sends the info back to the MainActivity
Intent output = new Intent();
output.putExtra(selectFunction.ACCESS_TOKEN_KEY, accessToken);
output.putExtra(selectFunction.MERCHANT_ID_KEY, merchantId);
output.putExtra(selectFunction.EMPLOYEE_ID_KEY, employeeId);
setResult(RESULT_OK, output);
finish();
}
}
});
// Loads the WebView
webView.loadUrl(url);
}
getting resulted url is https://www.clover.com/appmarket/m/MyMerchantID/apps/MyAppID?redirect_uri=http%253A%252F%252Flocalhost&response_type=token
do i need any other setting or changes to get expected result anything missing please let me know
Update 6 May 2017 i am getting proper result now the problem i facing to parse accestoken from the url i am using code block from clover ouh example
String accessTokenFragment = "#access_token=";
String merchantIdFragment = "&merchant_id=";
String employeeIdFragment = "&employee_id=";
int accessTokenStart = url.indexOf(accessTokenFragment);
int merchantIdStart = url.indexOf(merchantIdFragment);///problem is here because of wrong or diff sequence returns -1
int employeeIdStart = url.indexOf(employeeIdFragment);
if (accessTokenStart > -1) {
String accessToken = url.substring(accessTokenStart + accessTokenFragment.length(), merchantIdStart);
String merchantId = url.substring(merchantIdStart + merchantIdFragment.length(), employeeIdStart);
String employeeId = url.substring(employeeIdStart + employeeIdFragment.length(), url.length());
// Sends the info back to the MainActivity
Intent output = new Intent();
output.putExtra(selectFunction.ACCESS_TOKEN_KEY, accessToken);
output.putExtra(selectFunction.MERCHANT_ID_KEY, merchantId);
output.putExtra(selectFunction.EMPLOYEE_ID_KEY, employeeId);
setResult(RESULT_OK, output);
finish();
}
Here is the url i am getting
http://localhost:25110/Login.aspx?merchant_id=MYMERCHANTID&employee_id=MYEMPID&client_id=MYCLIENTID#access_token=MYACCESSTOKEN
so question is the sequence for all keys fixed? i dont think so according to mine scenario so how to get access token from that url? any help will be appericiated