Finding username in a widget's context
![]()
Hi All.
I'm writing some RTC widgets for a corporate dashboard. They're basically just implanted web pages from an external server (which processes my raw data and displays a summary). I've been asked to add the ability to annotate the results on display. Doing the actual annotation is easy enough - I can just POST the comment at the external server. But that's likely to leave many anonymous comments, which I don't want. I'd like to be able to prepend the user's name so that everyone knows who is making the comment - does anyone have a handy way to get at it? It's in the overall page, but I can't find anything in the iframe's DOM. Is this possible? Thanks! Vic. |
3 answers
![]()
The following enhancement is to track the proper solution for getting the user id in a gadget:
Provide a simple way to get current user id from an OpenSocial gadget (244518) As a temporary workaround, if you don't use lock domain support (hosting the gadget under another hostname/domain for security), then you can actually reach up and grab the user id from the parent window. Here's a quick hack you can use until the real solution comes along: window.top.com.ibm.team.repository.web.client.session.getAuthenticatedUserId() This should work in RTC as long as you're not using lock domain. You have to call this from the gadget itself, e.g. here's a test gadget that just prints out the user id: <?xml version="1.0" encoding="UTF-8"?> <Module> <ModulePrefs title="Test" height="300"> </ModulePrefs> <Content type="html"> <script type="text/javascript"> alert(window.top.com.ibm.team.repository.web.client.session.getAuthenticatedUserId()); </script> </Content> </Module> So if you have another iframe you're using inside there, you can tack that onto the iframe URL and read it from inside the iframe. |
![]()
An alternative which would not require reaching across the iframe/document boundary is to use the 'st' param from the iframe url.
'st' is the secure token, it is a colon delimited list of values. The first value is the userid. The gadget has access to that information.
|