Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

omniauth-yahoo-oauth2

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

omniauth-yahoo-oauth2

  • 1.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

omniauth-yahoo-oauth2

An unofficial, hastily-written Oauth2 OmniAuth strategy for Yahoo. Uses the authorization flow described at https://developer.yahoo.com/oauth2/guide/flows_authcode/.

Built using https://github.com/intridea/omniauth-oauth2.

Setup

gem install omniauth-yahoo-oauth2

Create an app at https://developer.yahoo.com/apps to get a Yahoo client ID and secret.

Usage

# In an initializer
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :yahoo_oauth2, yahoo_client_id, yahoo_secret, name: 'yahoo'
end

See https://github.com/intridea/omniauth for Omniauth instructions.

Notes

OmniAuth doesn't currently have built-in support for Basic Authentication for retrieving OAuth2 tokens, so YahooOauth2::Client overrides OAuth2::Client#get_token. Yahoo also requires redirect_uri to be set when refreshing the access_token, so YahooOauth2::AccessToken overrides OAuth2::AccessToken#refresh! to handle that.

As with other OAuth2 providers, Yahoo returns an access_token, a refresh_token, and an expiration time for the access_token. They are available in the credentials hash in the callback:

credentials = request.env.fetch('omniauth.auth').fetch(:credentials)
tokens_hash = {
  access_token:  credentials[:token],
  refresh_token: credentials[:refresh_token],
  expires_at:    credentials[:expires_at]
}

They should be saved to your application's database. You can use the access_token directly or use YahooOauth2::AccessToken for requests:

client = YahooOauth2::Client.new(YAHOO_CLIENT_ID, YAHOO_SECRET)
token  = YahooOauth2::AccessToken.from_hash(client, tokens_hash)
token.get(
  "https://social.yahooapis.com/v1/user/#{uid}/profile?format=json"
).parsed

And to refresh the access token once it has expired:

old_token = YahooOauth2::AccessToken.from_hash(client, tokens_hash)
if old_token.expired?
  new_token = old_token.refresh!
  new_token.to_hash # => update your database with this
end

TODO

FAQs

Package last updated on 28 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc