question

crono-shreerag avatar image
crono-shreerag asked

Unable to get authentication token from android app

Hi, I'm trying to implement an AVS app (not a companion) and I'm unable to get the authentication token. Upon calling AuthorizationManager.authorize() from within the app a web browser appears prompting me to sign in to my security profile. When I hit continue I am met with: "We're sorry! An error occurred when we tried to process your request. Rest assured, we're already working on the problem and expect to resolve it shortly" Any help would be appreciated, thanks!
alexa voice service
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Hello! From the description of your problem, it could be one of two issues. 1) Make sure that the api key you're using is from a security profile associated with an AVS product. You can check this by going to the developer portal, clicking on your AVS product, then clicking on the security profile tab. Make sure that you're using the API key associated with the security profile in the dropdown menu. 2) You might also be sending incorrect scope data. See https://forums.developer.amazon.com/forums/thread.jspa?threadID=9532 for an example of a guideline for Android AVS app implementation.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
Hi Eric, thanks for the response. I am using the key from the security profile listed under my app. For the scope data i am using this: SCOPE_DATA = "{\"alexa:all\":{\"productID\":\"CRONO_ALEXA_COMPANION_TEST\", \"productInstanceAttributes\":{\"deviceSerialNumber\":\"123456\"}}}"; As per the documentation. Is my product id wrong here? I am using the "Application Type ID" from the AVS app on developer portal.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
I also notice that every time i refresh the page with the key on developer portal it changes slightly, is this normal? Would any of these keys be correct?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
Your scope data looks correct, and don't worry about the API key changing. That is expected behavior. Unfortunately, I can't diagnose what could be going wrong without seeing what your code is doing. Can you send me your code? Additionally, I would suggest taking another look at https://forums.developer.amazon.com/forums/thread.jspa?threadID=9532&tstart=0 If you follow the code in that post, you should be able to get a working Android AVS app (assuming the api_key was copied correctly).
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
Here is my code right now, its very barebones and basically follows what is shown in that post. public class AlexaTestActivity extends AppCompatActivity{ private Toolbar toolbar; private AmazonAuthorizationManager mAuthManager; private Button mLoginButton; private static String TAG = "AlexaTestActivity"; private static final String SCOPE_DATA = "{\"alexa:all\":{\"productID\":\"testdevice1\", \"productInstanceAttributes\":{\"deviceSerialNumber\":\"123456\"}}}"; private static String[] APP_SCOPES = {"alexa:all"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alexa_test_layout); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY); mLoginButton = (Button) findViewById(R.id.login_with_amazon); mLoginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { doLogin(); } }); } private void getAccessToken() { mAuthManager.getToken(APP_SCOPES, new APIListener() { @Override public void onSuccess(Bundle response) { // Give the below access token to your AVS code String mAccessToken = response.getString(AuthzConstants.BUNDLE_KEY.TOKEN.val); if(mAccessToken == null){ Log.d(TAG, "Null access token"); }else{ Log.d(TAG, "Got access token: " + mAccessToken); } } @Override public void onError(AuthError ae) { Log.d(TAG, "Did not get access token"); } }); } private void doLogin() { Bundle options = new Bundle(); options.putString(AuthzConstants.BUNDLE_KEY.SCOPE_DATA.val, SCOPE_DATA); Log.d(TAG, SCOPE_DATA); mAuthManager.authorize(APP_SCOPES, options, new authlistener()); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; } return super.onOptionsItemSelected(item); } private class authlistener implements AuthorizationListener{ @Override public void onSuccess(Bundle response) { runOnUiThread(new Runnable() { public void run() { getAccessToken(); // Get the access token } }); } @Override public void onError(AuthError ae) { Log.e(TAG, "AuthError during authorization", ae); runOnUiThread(new Runnable() { @Override public void run() { showAuthToast("Error during authorization. Please try again."); } }); } @Override public void onCancel(Bundle cause) { Log.e(TAG, "User cancelled authorization"); runOnUiThread(new Runnable() { @Override public void run() { showAuthToast("Authorization cancelled"); } }); } } private void showAuthToast(String authToastMessage){ Toast authToast = Toast.makeText(getApplicationContext(), authToastMessage, Toast.LENGTH_LONG); authToast.setGravity(Gravity.CENTER, 0, 0); authToast.show(); }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
The browser is giving me an "ERR_UNKNOWN_URL_SCHEME" on android 5.1 if that helps at all. This is after hitting continue to login to the security profile.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
Ok It seems that upon hitting continue the browser serves up this address amzn://com.cronologics.android.companion?code=ANZpzLlLCzXgAUlXShfO&scope=alexa%3Aall&state=clientId%3Damzn1.application-oa2-client.67599357f87b4145a6c1fd8cd227cf3e%26redirectUri%3Damzn%3A%2F%2Fcom.cronologics.android.companion%26clientRequestId%3D55da5711-d1f5-4b5c-83a7-195ef1d71184%26com.amazon.identity.auth.device.authorization.return_auth_code%3Dfalse Which I think is supposed to redirect back to the app, but for some reason is giving me the url error, does that sound accurate?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
If you look at the last subsection of part 4 here (Add an Authorization Activity to your project), you'll see what you need to do: http://login.amazon.com/android
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

crono-shreerag avatar image
crono-shreerag answered
perfect! thanks so much. Sorry for the confusion, dont know how I missed that section.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Eric@Amazon avatar image
Eric@Amazon answered
No problem! Glad I was able to help
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.