Giter Club home page Giter Club logo

Comments (7)

CarlosMAguilar avatar CarlosMAguilar commented on June 15, 2024

Modifying code and running inside
"this.cordova.getActivity().runOnUiThread(new Runnable() {..."
didn't help

from azure-activedirectory-library-for-cordova.

sgrebnov avatar sgrebnov commented on June 15, 2024

@CarlosMAguilar - could you please post any simple code snippet which could be used to verify this case?

from azure-activedirectory-library-for-cordova.

CarlosMAguilar avatar CarlosMAguilar commented on June 15, 2024

hi.
I have reproduced this issue with this considerations:
Phone and OS as follows

screenshot_2016-02-11-13-32-55

Application: multipage (Login page and more modules)

I have done a simple test as follows:

in page 1, invoke with a button:

function testAdal(){ /*test database connection*/ DATABASE_ = window.openDatabase(DATABASE_INTERNAL_NAME_, DATABASE_VERSION_, DATABASE_CAPTION_NAME_, DATABASE_SIZE_); console.log(DATABASE_); //prepare error function var fn_onError = function(e){ console.log(e); }; //call to creation of context Microsoft.ADAL.AuthenticationContext.createAsync("AUTHORITY_URL").then(function(context_){ //aquire token context_.acquireTokenAsync("RESOURCE_URL", "APP_ID", "REDIRECT_URL").then(function (authResponse_) { //token is aquired correctly console.log(authResponse_.accessToken); //navigate to another page App.MoveToURL("Start.html"); }, fn_onError); }, fn_onError); }

I include an image because it can help understand this code (but is just the same).
code1

As you can see, I create context and try to acquire a token. Everything works as expected and this token is printed to console.

So far, everything is fine.

After that, I move to another page, lets say page 2, where I can invoke next function, trying to open database connection:

function testDB(){ DATABASE_ = window.openDatabase(DATABASE_INTERNAL_NAME_, DATABASE_VERSION_, DATABASE_CAPTION_NAME_, DATABASE_SIZE_); console.log(DATABASE_); }

code2

The function fails with the mentioned error. Below is the LogCat output. Note in blue the error and in red the consecuence

code3

I can confirm after some research that this is a common error in authentication plugins with cordova android (facebook for example), none of the forums expose an answer, they just say they "fixed" the plugin and ask users to reinstall/update.

As I said I tried to modify the code at CordovaAdalPlugin.java enclosing the code inside a

`
this.cordova.getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {

...
`
But this didn't help.

My workaround was to acquire token at login page, save whatever needs to be saved (in order to "save session" and don't ask the user again for the credentials) and restart my app (with a custom call to my own plugin) with code below. This also is Java:

public void RestartApp(){ Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage( getBaseContext().getPackageName() ); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); finish(); startActivity(i); }

Hope this helps.

from azure-activedirectory-library-for-cordova.

sgrebnov avatar sgrebnov commented on June 15, 2024

Confirm this issue (stable repro).

from azure-activedirectory-library-for-cordova.

sgrebnov avatar sgrebnov commented on June 15, 2024

The exact same behavior is reported here but it seems to be already resolved in WebView. But I can still see it in conjunction with ADAL native library as reported above. This might be hard to understand issue cause so you can use the following workarounds to get it working until this is resolved (please also note that websql api is obsoleted and no longer maintained):

  1. Use https://github.com/litehelpers/Cordova-sqlite-storage plugin. This plugin utilizes SQLite database instead of WebSQL database.
  2. Override window.openDatabase with own DroidDB_OpenDatabase similar to as it is showed here

from azure-activedirectory-library-for-cordova.

CarlosMAguilar avatar CarlosMAguilar commented on June 15, 2024

Thanks for your help. I am still looking for a solution but, so far, I am able to bypass with the workaround. I always check over the internet for changes on this, If I get something I will post it here.

from azure-activedirectory-library-for-cordova.

sgrebnov avatar sgrebnov commented on June 15, 2024

Thanks @CarlosMAguilar

from azure-activedirectory-library-for-cordova.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.