Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap and OAuth2

I am developing a PhoneGap application and require my users to sign in through Google with OAuth2. Is this possible directly through JavaScript? I have almost no experience with JavaScript (and jQuery).

What are the options? I have thought of a cumbersome alternative which involves posting the username/password to an application I have hosted on a server which then takes care of logging in. Then the PhoneGap app will have to ask the server if the authentication was successful. However, I was hoping there would be a simpler way.

What is the best way signing in through Google on a PhoneGap app?

like image 314
whirlwin Avatar asked Mar 20 '12 16:03

whirlwin


People also ask

What is PhoneGap and how to use it?

PhoneGap is a software development framework by Adobe System, which is used to develop mobile applications. To develop apps using PhoneGap, the developer does not require to have knowledge of mobile programming language but only web-development languages like, HTML, CSS, and JScript.

What is OAuth authentication for Exchange Online in Office 365?

You can use the OAuth authentication service provided by Azure Active Directory to enable your application to connect with IMAP, POP or SMTP protocols to access Exchange Online in Office 365. To use OAuth with your application you need to:

Which OAuth2 protocols are supported for Office 365?

OAuth2 support for IMAP, POP, SMTP protocols as described below is supported for both Microsoft 365 (which includes Office on the web) and Outlook.com users. If you're not familiar with the OAuth 2.0 protocol, start by reading the OAuth 2.0 protocol on Microsoft identity platform overview.

How to authenticate a shared mailbox connection using OAuth?

In case of shared mailbox access using OAuth, application needs to obtain the access token on behalf of a user but replace the userName field in the SASL XOAUTH2 encoded string with the email address of the shared mailbox. To authenticate a IMAP server connection, the client will have to respond with an AUTHENTICATE command in the following format:


1 Answers

I have managed to get it working! I'm posting my thoughts here because I had a hard time finding the answer after hours of searching the web.

The important steps are:

  • Make sure ChildBrowser works properly
  • Setup a function that will listen to page changes window.plugins.childBrowser.onLocationChange = function(fooUrl) { console.log(fooUrl); }
  • Build the URL with the query string as described in this tutorial
  • Point ChildBrowser to the URL
  • When the user logs in, you will be able to extract the session token from fooUrl

If you still don't know how to do this, have a look at this Android app. (There is a lot of code, and it might seem overwhelming, so I suggest only going for this as a last resort)

like image 190
whirlwin Avatar answered Sep 24 '22 00:09

whirlwin