Yammer REST API: How to get access tokens for external networks?

前端 未结 3 1277
[愿得一人]
[愿得一人] 2020-12-10 22:22

I\'m working on an ASP.NET web application that reads data from Yammer. I\'ve successfully acomplished authentication and getting messages from the \"home\" network.

3条回答
  •  感动是毒
    2020-12-10 23:00

    So far what i have discovered is this: Due to some cross domain restriction, the SDK creates a hidden iframe on the page to serve as a proxy bridge to use the users primary network credentials and get access to external network resources. The network parameter is the key in the puzzle.

    The obtained token can be then manually set for further requests whenever the page is reloaded, avoiding the login window to show up again.

    yam.platform.login({ network: '{your-permalink-goes-here}' }, function (data) {
    
        console.log('login-status: ',data)
        if(data.status ==='connected')
            yam.platform.request({
                url: "oauth/tokens.json"     
                , method: "GET"
                , success: function (tokens) { console.log('user-tokens:',tokens); }
                , error: function (err) { alert("There was an error with the request."); }
            });
    })
    

    Then for next requests, setAuthToken does the trick.

    yam.platform.setAuthToken('{the-token-goes-here}'))
    

提交回复
热议问题