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

Notice about incompatibility + new approach using passport-oauth2 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Passport-Yahoo-OAuth

| Notice (October 2022): |
| :------------- |
| This module was designed for a previous version of Yahoo! OAuth API (v1.0a) and is no longer compatible with the current version of Yahoo! OAuth API (v2.0). A working alternative is to use [passport-oauth2](https://github.com/jaredhanson/passport-oauth2), configured to [Yahoo! OAuth API (v2.0) specifications](https://developer.yahoo.com/sign-in-with-yahoo/). Example code can be found [here](https://github.com/jaredhanson/passport-yahoo-oauth/tree/master/examples/example-oauth2). |

---
### Original README:
---

[Passport](http://passportjs.org/) strategies for authenticating with [Yahoo!](http://www.yahoo.com/)
using the OAuth 1.0a API.

Expand Down
3 changes: 3 additions & 0 deletions examples/example-oauth2/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export yahooConsumerKey="yourConsumerKey"
export yahooConsumerSecret="yourConsumerSecret"
export yahooCallbackURL="yourCallbackURL"
41 changes: 41 additions & 0 deletions examples/example-oauth2/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var passport = require("passport");
var OAuth2Strategy = require("passport-oauth2");
var yahooConsumerKey = process.env.yahooConsumerKey;
var yahooConsumerSecret = process.env.yahooConsumerSecret;
var yahooCallbackURL = process.env.yahooCallbackURL;
var fetch = require("node-fetch");

passport.serializeUser(function (user, done) {
done(null, user);
});

passport.deserializeUser(function (user, done) {
done(null, user);
});

// ------------------------------------
// Yahoo Login OAuth2 passport strategy
// ------------------------------------
passport.use(new OAuth2Strategy({
authorizationURL: `https://api.login.yahoo.com/oauth2/request_auth_fe?client_id=${yahooConsumerKey}&response_type=code&redirect_uri=${yahooCallbackURL}&language=en-US`,
tokenURL: "https://api.login.yahoo.com/oauth2/get_token",
clientID: yahooConsumerKey,
clientSecret: yahooConsumerSecret,
callbackURL: yahooCallbackURL
},
async function (accessToken, refreshToken, profile, cb) {
let authHead = "Bearer " + accessToken;
var profile = await fetch("https://api.login.yahoo.com/openid/v1/userinfo", {
method: "GET",
headers: {
"host": "api.login.yahoo.com",
"Authorization": authHead
}
})
.then(response => response.json())
.catch(error => console.log("error", error));
return cb(null, profile);
}
));

module.exports = passport;
15 changes: 15 additions & 0 deletions examples/example-oauth2/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var passport = require("passport.js");

module.exports = function (app) {

app.get("/auth/yahoo/callback",
passport.authenticate("oauth2", { failureRedirect: "/oauth-error", session: true }),
function (req, res) {
//
// Your code, post-authentication
//
// Example:
res.json(req.user);
});

}