Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to get additional user info #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joe1chen
Copy link
Contributor

Gets additional data from /v1.1/teachers/{id} or /v1.1/students/{id} if option get_user_info is set to true.

Example with devise:

config.omniauth :clever, Settings.clever.client_id, Settings.clever.client_secret, { get_user_info: true }

if user_type && user_id
@raw_user_info = access_token.get("/v1.1/#{user_type}s/#{user_id}").parsed
end
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have exactly the same use case, I needed more info than what the /me endpoint provided. But instead of building a URL from parts, I used the links collection that comes in the JSON returned from the /me endpoint. (An example of the links collection is at https://dev.clever.com/instant-login/users)

What do you think of something like this? This approach lets the API tell us where the canonical endpoint is for the user versus building up a URL from parts.

  extra do
    {
      raw_info: me_attrs,
      canonical: canonical_attrs
    }
  end                                                                                                                                                                                                                                                                                                                            

  def me_attrs
    @me_attrs ||= access_token.get('/me').parsed
  end

  def canonical_attrs
    @canonical_attrs ||= access_token.get(canonical_endpoint).parsed
  end

  def canonical_endpoint
    me_link('canonical').fetch('uri', '/me')
  end

  def me_link(rel)
    me_attrs.fetch('links', []).detect { |link| link['rel'] == rel } || {}
  end

@cdsmith16
Copy link

Thanks @jbusser for the update! We very much recommend using links!!

@jbusser
Copy link

jbusser commented Jan 18, 2017

Could we talk about either merging this PR or closing it? I am relying on a forked version of this gem to deliver this feature, and it would be nice to be back on a maintainer-supported gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants