function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AK-2AK-2 

Canvas application using OAuth- unable to retrieve Token

I am playing with a canvas app that's a couple of web pages (html) with some js. I am using oauth for authenticating with Salesforce. In the javascript, I have index.html which starts the authentication flow using Sfdc.canvas.oauth.login as shown below. The page redirects to index1.html after login:
 
if (! Sfdc.canvas.oauth.loggedin()) {
                uri = Sfdc.canvas.oauth.loginUrl();
                Sfdc.canvas.oauth.login(
                    {uri : uri,
                        params: {
                            response_type : "token",
                            client_id : "code",
                            redirect_uri : encodeURIComponent(
                                "https://localhost:8181/index1.html")
                        }});
            }
            else {
                Sfdc.canvas.oauth.logout();
                login.innerHTML = "Login";
                Sfdc.canvas.byId("oauth").innerHTML = "";
            }

What I am noticing is that even when I am logged into my dev org, the page Sfdc.canvas.oauth.loggedin() is always false. If I am logged in, the page correctly redirects me to my callback page index1 and if I am not logged into the salesforce on the browser, the app correctly redirects me to the login page (I am using mydomain). But after I log-in, I can't seem to get the context or the token in index1.html here:
 
var login    = Sfdc.canvas.byId("login"),
                loggedIn = Sfdc.canvas.oauth.loggedin(),
                token = Sfdc.canvas.oauth.token();

What am I missing? Why is the token blank?
Thank you.
Best Answer chosen by AK-2
AK-2AK-2
I figured out the issue with the token. The token was stripped by the angular framework I was using. Will need to look at why that's happening but at least now I know what the issue was.

All Answers

AK-2AK-2
I figured out the issue with the token. The token was stripped by the angular framework I was using. Will need to look at why that's happening but at least now I know what the issue was.
This was selected as the best answer
Mango OrangeMango Orange
Did you find the solution for this?  I am facing exactly same issue.  Even If I am logged in, Sfdc.canvas.oauth.loggedin() always return false.