I continued to be plagued with a highly frustrating problem thats driving me crazy.
I have a problem whereby the token auth_token issued by my Android App is failing in my web-app.
This is the line of code from the Android App.
webview.loadUrl("https:/domainname.com/cloverlogin?authtoken=" + result.authToken + "&merchantid=" + result.merchantId +"&appid=" + result.appId);
Attached are two images I've captured from Genymotion. The first is when I use the authToken passed from the Android App which results in an error 401 when I attempt an API call. The second is when I hard code the authtoken to be the one created in Sandbox against this merchant. With the second image you can see the authtoken I've used is not the same as the one passed to my PHP endpoint . You can clearly see the auth_token passed from the Android app is failing with an error 401.
I have set all the permissions to ticked against the app and I have uninstalled and reinstalled the app several times. I have done this on both the Emulator and the Clover Station with the same results.
Any ideas?
Robin
EDIT
Here is all the code from my Android App
MainAcvtivity.java
package com.fashionservers.www.fsinventorymanagement;
import android.accounts.Account;
import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.view.Window;
import com.clover.sdk.util.CloverAccount;
import com.clover.sdk.util.CloverAuth;
import com.clover.sdk.v1.app.AppNotification;
import com.clover.sdk.v1.app.AppNotificationReceiver;
public class MainActivity extends AppCompatActivity {
private Account mAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
// Retrieve the Clover account
if (mAccount == null) {
mAccount = CloverAccount.getAccount(this);
if (mAccount == null) {
finish();
}
// Use this account to get the access token (and other Clover authentication data)
getCloverAuth();
}
}
private void getCloverAuth() {
// This needs to be done on a background thread
new AsyncTask<Void, Void, CloverAuth.AuthResult>() {
@Override
protected CloverAuth.AuthResult doInBackground(Void... params) {
try {
return CloverAuth.authenticate(MainActivity.this, mAccount);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(CloverAuth.AuthResult result) {
WebView webview = new WebView(getBaseContext());
setContentView(webview);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://www.fashionservers.com/stores/clover_login?auth_token=" + result.authToken + "&merchant_id=" + result.merchantId +"&app_id=" + result.appId);
}
}.execute();
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fashionservers.www.fsinventorymanagement">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Fashion Inventory"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:minSdkVersion="17"
android:versionCode="4"
android:versionName="4"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.fashionservers.www.fsinventorymanagement.MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="696dp"
android:layout_height="447dp"
android:layout_marginRight="432dp"
android:layout_marginTop="183dp"
android:visibility="visible"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>