Select to view content in your preferred language

IdentityManager's getCredential is not returning a deferred object.

1709
0
01-09-2017 08:24 AM
PalakBhojani
Deactivated User

I have an application with oAuth 2.0 authentication with the pop up. I followed the exact same tutorial from this website OAuth Popup | ArcGIS API for JavaScript 3.19 . Below is the current code I have for my application. I am able to sign in and get the token back and the pop up closes successfully. Since getCredential returns a deferred object i have a .then(function() {}) to take care of changing the display to show the user name. My application never hits the break point in the function for .then() or .otherwise() after the getCredential function call.

Am I missing something here that needs to be in the required statement? I am not getting any error messages upon debug. It looks like it signed in right but it just never catches on the promise to save the Credential object.

Any help is very much appreciated!


require([
"esri/arcgis/Portal",
"esri/arcgis/OAuthInfo",
"esri/IdentityManager",
"esri/ServerInfo",

"dijit/registry",

"dojo/query",
"dojo/dom-style",
"dojo/dom-attr",
"dojo/dom",
"dojo/on",
"dojo/_base/array",
"dojo/domReady!"
],

function (
arcgisPortal,
OAuthInfo,
esriId,
ServerInfo,

registry,
query,
domStyle,
domAttr,
dom,
on,
arrayUtils) {

var info = new OAuthInfo({
appId: "YourAppID",
portalUrl: "YourPortalUrl",
popup: true
});
esriId.registerOAuthInfos([info]);

on(dom.byId("sign-in"), "click", function (){
// user will be shown the OAuth Sign In page
esriId.getCredential(info.portalUrl + "/sharing", {
oAuthPopupConfirmation: false
}
).then(function (){
var currentToken = esriId.checkSignInStatus();
console.log(currentToken);
displayItems();
}).otherwise(
function (error){
console.log("Error occurred while signing in: ", error);
}
);
});

on(dom.byId("sign-out"), "click", function (){
esriId.destroyCredentials();
window.location.reload();
});

window.oauthCallback = function(token) {
accesstoken = token;
console.log("Token is: " + accesstoken);

};

function displayItems(){
new arcgisPortal.Portal("portalUrl").signIn().then(
function (portalUser){
console.log("Signed in to the portal: ", portalUser);

domAttr.set("userId", "innerHTML", portalUser.fullName);
domStyle.set("anonymousPanel", "display", "none");
domStyle.set("Navigation", "display", "block");
domStyle.set("personalizedPanel", "display", "block");

queryPortal(portalUser);
}
).otherwise(
function (error){
console.log("Error occurred while signing in: ", error);
}
);
}

function queryPortal(portalUser){
var portal = portalUser.portal;

var queryParams = {
q: "owner:" + portalUser.username,
sortField: "numViews",
sortOrder: "desc",
num: 20
};

portal.queryItems(queryParams).then(createGallery);
}
function createGallery(items){
var htmlFragment = "";

arrayUtils.forEach(items.results, function (item){
htmlFragment += (
"<div class=\"esri-item-container\">" +
(
item.thumbnailUrl ?
"<div class=\"esri-image\" style=\"background-image:url(" + item.thumbnailUrl + ");\"></div>" :
"<div class=\"esri-image esri-null-image\">Thumbnail not available</div>"
) +
(
item.title ?
"<div class=\"esri-title\">" + (item.title || "") + "</div>" :
"<div class=\"esri-title esri-null-title\">Title not available</div>"
) +
"</div>"
);
});

dom.byId("itemGallery").innerHTML = htmlFragment;
};
});

0 Kudos
0 Replies