1. Are you ready for the Galaxy S20? Here is everything we know so far!

Can I use Android WebView object for Google Authentication?

Discussion in 'Android Development' started by acenspades, Sep 21, 2021.

  1. acenspades

    acenspades Lurker
    Thread Starter

    I'm using Android Studio to update a login page that authenticates via Google. In the onCreate method, I have a function, called loadWebViewPage(), that loads up our authentication page that uses Google for auth. When loadWebViewPage() is called I have the following:

    private void loadWebViewPage()
    {

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    String userAgent = "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Mobile Safari/535.19";
    //Set WebView
    WebView webView =(WebView)findViewById(R.id.webView);
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setUserAgentString(userAgent);
    //Set WebSettings
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setSupportMultipleWindows(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
    webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    }

    webView.loadUrl("the url that redirects to sso page");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    LocalBroadcastManager.getInstance(getApplicationContext())
    .registerReceiver(loginBroadcastReceiver,
    new IntentFilter(LoginHelper.LOGIN_MESSAGE));

    }

    The onCreate method works fine; I get the page to load, users can enter their email and password. However when the users clicks the login button it does not want to load in Google authentication where they should be able to select which Google account they want to log in with.

    This line webView.loadUrl("the url that redirects to sso page") loads up a vendor hosted page that handles the sso authentication. If user enters an invalid email or incorrect email/password combination it does not allow them to proceed forward and presents a "login error' message.
    If user enters a valid Google email that is in the system linked by a userID, then it is supposed to present them with the Google option to either enter their password or select the appropriate Google account if they are logged into multiple Google accounts.

    I tried looking for a solution and what I've seen is the User Agent or Google doesn't support Webviews anymore to I need to setup a browser that handles auth then go back into app on successful login.

    I'm thinking the easiest solution would be to update the the User Agent variable. However, am I missing something or should be approaching this differently? I don't want to load an actual browser as we don't want users messing with the url address or having to worrying about the navigation buttons.

    Thanks
     


    #1 acenspades, Sep 21, 2021
    Last edited: Sep 21, 2021

    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Android WebView object
  1. Luca Bertoncello
    Replies:
    0
    Views:
    141
  2. sam_windsor
    Replies:
    10
    Views:
    479
  3. ironass
    Replies:
    1
    Views:
    265
  4. Philip1982
    Replies:
    0
    Views:
    368
  5. cinarrtolga
    Replies:
    0
    Views:
    1,131
  6. hk1337
    Replies:
    0
    Views:
    3,909
  7. Debsmita Paul
    Replies:
    1
    Views:
    5,353
  8. julianov
    Replies:
    0
    Views:
    794
  9. Guillermo Esquivel
    Replies:
    0
    Views:
    996
  10. Nagori
    Replies:
    0
    Views:
    574

Share This Page

Loading...