Yahoo API with Ruby on Rails and OAUTH2

本小妞迷上赌 提交于 2019-12-02 02:42:30

Don't ask me why but Yahoo has made it very hard to find their OAuth 2.0 documention. I found it, though!

Also, pretty "awesome" that you get a refresh_token without needing to explicitly ask the user for "offline" permissions. In my opinion, this is a security concern for Yahoo. Both Google and Microsoft require explicit "offline" access.

require 'oauth2'

OAuth2::Client.new(Rails.application.secrets.yahoo_consumer_id, Rails.application.secrets.yahoo_consumer_secret, site: 'https://api.login.yahoo.com', authorize_url: '/oauth2/request_auth', token_url: '/oauth2/get_token')
client.auth_code.authorize_url(redirect_uri: redirect_uri, headers: { "Authorization" => basic_authorization })
token = client.auth_code.get_token(code, redirect_uri: redirect_uri)

# Later
token.refresh!

As per quatermain's request, I post my solution as answer here:

https://docs.google.com/document/d/1SdGSfakQM3ZuiqJK7keXhOfh6310-z_h0THl1_Jswxk/pub

P/S: There is some mistype I made within the document, as below:

  • The sentence: "I don't this this URL affect to authentication process..." --> shoud be "I don't think this URL affect to authentication process..."

  • The word "and ready through" --> should be "and read through"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!