简体   繁体   中英

How do I specify a custom field for uid in an omniauth strategy?

I'm building an omniauth strategy to work with the Suunto API. The request to their token_url returns a response that includes a user key/value:

{
  "access_token":"ACCESS_TOKEN",
  "token_type":"bearer",
  "refresh_token":"REFRESH_TOKEN",
  "expires_in":86399,
  "scope":"workout",
  "ukv":"1",
  "uk":"SOME_VALUE",
  "user":"UID",
  "jti":"SOME_VALUE"
}

This is meant to be used as the uid value.

Based on the Declarative Configuration docs I tried this, with no luck:

option :fields, [:user]
option :uid_field, :user

This doesn't work because the field isn't present in the request, it's in the token_url response:

uid do
  request.params[options.uid_field.to_s]
end

The Defining the Callback Phase docs has a note about credentials , but there's no usage example.

What should I add/edit in my strategy that will tell it to set the uid value to the user that's returned from the token request's response?

Ah. I figured it out: This goes into the strategy:

uid { raw_info["user"] }

def raw_info
  @raw_info ||= access_token
end

At that point in raw_info , access_token is the hash that I included in the opening of my question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM