-
Notifications
You must be signed in to change notification settings - Fork 58
Add option to get additional user info #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,8 @@ class Clever < OmniAuth::Strategies::OAuth2 | |
| :token_url => 'https://clever.com/oauth/tokens' | ||
| } | ||
|
|
||
| option :get_user_info, false | ||
|
|
||
| # This option bubbles up to the OmniAuth::Strategies::OAuth2 | ||
| # when we call super in the callback_phase below. | ||
| # **State will still be verified** when login is initiated by the client. | ||
|
|
@@ -45,18 +47,35 @@ def callback_phase | |
| uid{ raw_info['data']['id'] } | ||
|
|
||
| info do | ||
| { :user_type => raw_info['type'] }.merge! raw_info['data'] | ||
| { :user_type => raw_info['type'] }.merge(raw_info['data']).merge(raw_user_info['data']) | ||
| end | ||
|
|
||
| extra do | ||
| { | ||
| 'raw_info' => raw_info | ||
| 'raw_info' => raw_info, | ||
| 'raw_user_info' => raw_user_info | ||
| } | ||
| end | ||
|
|
||
| def raw_info | ||
| @raw_info ||= access_token.get('/me').parsed | ||
| end | ||
|
|
||
| def raw_user_info | ||
| return @raw_user_info if @raw_user_info | ||
|
|
||
| @raw_user_info = {} | ||
|
|
||
| if options.get_user_info | ||
| user_type = raw_info['type'] | ||
| user_id = raw_info['data']['id'] | ||
| if user_type && user_id | ||
| @raw_user_info = access_token.get("/v1.1/#{user_type}s/#{user_id}").parsed | ||
| end | ||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 |
||
|
|
||
| @raw_user_info | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍