How To Lookup Current User Email Address Via JavaScript

4,212 views
Skip to first unread message

Ryan Marsh

unread,
Feb 4, 2014, 2:38:46 PM2/4/14
to canvas-l...@googlegroups.com
I'm currently using Canvas Opensource and link to content in another tool. This other tool has a URL API that can accept a display name and email address. I was able to add a custom JavaScript file that pulled the ENV.current_user.display_name to get that, but how do I get the email address?

I went looking in the ENV.current_user object and didn't see any methods or properties for Email.

Thanks,

Eric Korb

unread,
Feb 6, 2014, 9:11:34 AM2/6/14
to canvas-l...@googlegroups.com
Ryan:

You should look to use LTI.  This will give more control and authenticate access to your app .

Get more LTI info here: https://www.edu-apps.org/index.html

Eric @accreditrust

Ryan Marsh

unread,
Feb 6, 2014, 12:31:27 PM2/6/14
to canvas-l...@googlegroups.com
Hi Eric,

I've already looked at LTI and am planning on building an integration in the future, but for right now all I need is to pull the email address. Hosting a separate server, doing OAuth, and building an app is really overkill for what I need at the moment. All I want is to do right now is use JavaScript to write the current user's email address into an anchor tag.
Message has been deleted

Eric Korb

unread,
Feb 6, 2014, 12:49:15 PM2/6/14
to canvas-l...@googlegroups.com
The other way to get this info is via the API.  Information like email address is hidden for obvious reasons.  I don't believe email would be accessible via javascript.  You might be able to lift it via jquery from the user's profile page.  But, that would require the user to take action to fire your script.

The right way to do this is via LTI and API.  You don't need oauth for LTI to work in your own installation of Canvas.  If you want your app to work elsewhere, you'll want oauth.  Just create app key and build an application that has a simple chrome that uses the Canvas API to get the user's id or email address and submit it to your app.  The app can show up in a frame or pop-out depending on your parameters.

Need help, let me know.

Eric

Graham Ballantyne

unread,
Feb 6, 2014, 1:02:05 PM2/6/14
to canvas-l...@googlegroups.com
You can get the user’s email address from the API. A user can make a call to the API as themself to get their own profile data.

$.get(‘/api/v1/users/self/profile’, function(profile) {
    console.log(profile.primary_email);
});

Keep in mind that a user can register multiple email addresses with Canvas; only their primary address will be returned by the API. 

– gnb


--
 
---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Eric Korb

unread,
Feb 6, 2014, 1:12:20 PM2/6/14
to canvas-l...@googlegroups.com
@Graham,  Nice simple answer!

@Ryan, just one word of caution, I suggest pulling "login_id", not primary email address since that can change and not controlled by institution who sets up the Canvas account. You could end up with miss-matches.

$.get(‘/api/v1/users/self/profile’, function(profile) {
    console.log(profile.login_id);
});

Eric

Graham Ballantyne

unread,
Feb 6, 2014, 1:23:52 PM2/6/14
to canvas-l...@googlegroups.com
login_id may or may not be an email address, especially when using self-hosted OSS Canvas. For example, we use CAS in our self-hosted Canvas, which uses LDAP uids. So, I log in to Canvas as `grahamb`, and thus my login_id is `grahamb`. Now, in our case, this directly maps to an email address by adding @sfu.ca to the login_id, but that may or not be the case everywhere.

– gnb

Eric Korb

unread,
Feb 6, 2014, 1:47:33 PM2/6/14
to canvas-l...@googlegroups.com
Greate point Graham.  I forgot about other authentication methods that could be in use.

Eric

On Thursday, February 6, 2014 1:02:05 PM UTC-5, Graham Ballantyne wrote:

Ryan Marsh

unread,
Feb 6, 2014, 4:35:54 PM2/6/14
to canvas-l...@googlegroups.com
Thanks all... this is EXACTLY what I needed.

Like Graham, I'm using LDAP for Authentication but can easy append the necessary information to format it into an email. Thanks for the help all!
Reply all
Reply to author
Forward
0 new messages