Paul Williamson
Paul Williamson

Reputation: 21

Yammer JS SDK Authenticating when user is logged into another network

There seems to be a problem if you use the SDK login function to login while the user is connected to another network. All the API calls fail and there seems to be no way to get back to the home network to authenticate.

Here is the code required to test this problem:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Yammer Login</title>
<script type="text/javascript" data-app-id="{INSERT APP ID}" src="https://c64.assets-yammer.com/assets/platform_js_sdk.js"></script>
</head>
<body>
<div id="Envelope"> 

<div><span id="yammer-login"></span></div>
<div><input type="button" onclick="getUserInfo()" value="Get User Info"></div>
<script>
    yam.connect.loginButton('#yammer-login', 
    function (resp) { 
        console.log(resp);
    }); 

    function getUserInfo() {
        yam.platform.request({
            url: 'users/current.json',
            method: "GET",
            success: function (r) { console.log("GOT RESPONSE"); console.log(r); },
            error:   function (r) { console.log(r.statusText) }
          });           

    }
</script>
</div>
</body>
</html>

If the user is logged into their home network the login code works and you can press the button to get the users information (note javascript origins are correctly configured).

You you go into the yammer interface and select another network it not longer works.

Here is what the console output looks like:

 GET https://www.yammer.com/platform/login_status.json?

client_id={Client ID} 403 (Forbidden)
platform_js_sdk.js:26 XHR finished loading: GET "https://www.yammer.com/platform/login_status.json?client_id={ClientID}".
test.php:18 Object {access_token: Object, success: true, status: "connected", authResponse: true}
api.yammer.com/api/v1/users/current.json:1 GET https://api.yammer.com/api/v1/users/current.json 
test.php:1 XMLHttpRequest cannot load https://api.yammer.com/api/v1/users/current.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://webserver.com' is therefore not allowed access. The response had HTTP status code 401.
test.php:26 error
api.yammer.com/api/v1/users/current.json:1 GET https://api.yammer.com/api/v1/users/current.json 
test.php:1 XMLHttpRequest cannot load https://api.yammer.com/api/v1/users/current.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://webserver.com' is therefore not allowed access. The response had HTTP status code 401.
test.php:26 error

It appears that the login token that is being uses belongs to the other network and therefore access is restricted.

Upvotes: 2

Views: 947

Answers (1)

IsraelWebDev
IsraelWebDev

Reputation: 13

Based on Yammer REST API: How to get access tokens for external networks? you need to apply to deploy to the Global App Directory. Specify by e-mail to the Biz Dev rep that your app requires Global Access (even without being published in the App Directory). This resolves the issue.

see slide 5 of http://about.yammer.com/assets/yammer-apps-next-steps.ppt

Upvotes: 1

Related Questions