AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

I am trying to implement oauth2 authentication. I have started with the salesforce plugin and then I'm using it to log into dropbox api. For the redirect_uri callback from dropbox I have to use the appery URL: http://appery.io/app/view/0c17c2c9-94... and have it set to public.

This works but is forever dependant on appery.io and having my app set to public in this way. I don't want this, is there another way?

Looking at Oauth2 documentation on mobile app flow, it seems the way to do this is by using a custom uri protocol (iOS) or URL matching patterns which will launch the native app (android).

Is this possible to do with an appery app?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Oauth2 redirect_uri

Hi Aric,

If you don't tick 'Public', it doesn't work, right?

AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

Correct. Without public checked, it asks you to log into an appery account.

While this works for now, I don't want to have to always redirect through appery.

How does appery get that redirect back to my app?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Oauth2 redirect_uri

Hello! Looks like you've done something wrong... You should open Login window in new inAppBrowser window and track there redirect to Appery.io page. Once it's redirected close inAppBrowser window and continue work in app. There is no need to do public anything. Please check an example here https://getsatisfaction.com/apperyio/...

AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

ok well I was using the salesforce plugin code. What you say makes sense though. So I can just make up whatever I want for the redirect uri because its going to catch that with the event handler?

AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

I still cant get this to work. Here is the javascript I am using:
pre
function doLogin() {

Code: Select all

 // as we render all pages into one file, let's check if this is a callback 
 if (window.location.href.indexOf("access_token") == -1) { 

     var client_id = SF_Settings['client_id']; 
     var redirect_url = SF_Settings['redirect_url']; 
     var login_url = SF_Settings['login_url']; 

     var url = login_url + "?response_type=token&client_id=" + client_id + "&redirect_uri=" + encodeURI(redirect_url); 

     // let's go to Salesforce to login 
     //window.open(url, "_self"); 

     var ref = window.open(url, '_blank', 'location=no'); 
     ref.addEventListener('loadstart', function(event) { 
         if (event.url.indexOf(redirect_url) === 0) { 
             /* if user successfully logged in */ 
             ref.close(); 
             var vars = parseUrlVars(event.url); 
             localStorage.setItem('access_token', "Bearer " + vars.access_token); /* store secret code */ 
             localStorage.setItem('instance_url', vars.instance_url); 
             Appery.navigateTo('SF_UsingAPI', { 
                 reverse: false 
             }); /* Navigate to page 'result' */ 
         } 
     }); 

 } else { // yes, this is a callback 
     alert("this shouldnt happen now"); 
     // save token, url into local storag 
     saveAuthCodeInLocalStorage(); 
     // navigate to Contacts page 
     Appery.navigateTo('SF_UsingAPI', { 
         reverse: false 
     }); 

 } 

}
/pre

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Oauth2 redirect_uri

Hi Aric,

1) You can use oAuth2 for authorization on WordPress: http://developer.wordpress.com/docs/o...
It's very safe mechanism we can recommend you.
2) If there is an appropriate API - yes, sure.
3) You can use any library to create QR, for example: http://larsjung.de/qrcode/

AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

I think you might have responded to the wrong message? I wasnt asking about wordpress or QR codes.. ?

In my situation, using the above js code, the 'loadstart' event listener is never getting called. I cant figure out why because the code looks correct.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Oauth2 redirect_uri

Hello! Sorry for a late reply and misunderstanding.
Could you clarify where did you put code posted above? What happens when you run this code? Does login page open? What exactly doesn't work, are there any errors in console?

AricCaley
Posts: 0
Joined: Thu Jul 18, 2013 11:22 pm

Oauth2 redirect_uri

I am using the salesforce plugin with few changes. The javascript doLogin() is run on load of the start page in my app.

The callback should be going to the loadstart function, and not to the other else statement, so I put in that alert, and indeed that alert comes up "this shouldnt happen now". It seems that addEventListener() is not working.

Now, I understand that it probably will only work inside of a native app and not inside a browser test, because it relies on phonegap native code. But I've tried with an .apk exported from appery and it does not work.

Return to “Issues”