Select to view content in your preferred language

OAuth 2.0 JS API 4.4 error

1232
4
07-10-2017 01:47 PM
Yunpiao_WhitneyBai
Emerging Contributor

Hello,

I'm trying to implement OAuth login for my web app. I followed the API sample here : Access ArcGIS Online items using OAuthentication | ArcGIS API for JavaScript 4.4 . It works for me when I open the live demo, but when I download the file and open it in chrome locally. I got this error: 

How should I fix this? 

thanks!

4 Replies
ReneRubalcava
Honored Contributor

You need to update it with your own appId and set up the redirect to your dev machine.

Implementing App Login | ArcGIS for Developers 

Yunpiao_WhitneyBai
Emerging Contributor

Hello Rene, 

thanks for the reply. I tried that already. But the error is the same. I am confused that should I modify the code 

esriId.getCredential(info.portalUrl + "/sharing")

?  I replace this code with 

window.open('https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id='+clientId+'&response_type=token&expi...' + window.encodeURIComponent(redirectUri), 'oauth-window', 'height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes')

And it works. But I do not want hard code this directURL. What should I do? 

Whitney

ReneRubalcava
Honored Contributor

Go to your Online page, something <user>.arcgis.com, go to Content, filter by Apps/Registered Apps

Click on your app, go to settings.

Under settings, go to Application Settings area and click on Registered Info button.

Update the URI redirects here, this is what one of mine looks like.

Yunpiao_WhitneyBai
Emerging Contributor

Hi Rene,

Thanks for the instruction. Similarly, I added my portals in the app 

esriId.getCredential(info.portalUrl+"/sharing");

The getCredential function now works and showing the  AGOL login form

However, after the login, nothing happens. 

esriId.checkSignInStatus(portalUrl+"/sharing").then( function() {
//displayItems();
   alert("ssss");
}).otherwise( function() {
// Anonymous view
domStyle.set("anonymousPanel", "display", "block");
domStyle.set("personalizedPanel", "display", "none");
}
);

Neither the resolved or rejected function executes after a successful login. 

Should I change the parameter (portalUrl+"/sharing") to somthing else? 

Also, after I login and direct to another html page that also requires some feature access, how can I check it is already login and avoid a second login? 

Whitney

0 Kudos