Comments (11)
Yes @marshallswain has it almost correct. It needs to be whatever the passport strategy requires for params. So in this case:
{
strategy: 'facebook-token',
access_token: 'your facebook access token'
}
from authentication-oauth2.
We definitely need a guide that shows how to do this. I know you need. To use the passport-Facebook-token strategy. I'm not sure what else is needed.
from authentication-oauth2.
No, I didn't. After trying, I will write about it
from authentication-oauth2.
So @00Freezy00 wrote up a great tutorial about this in https://medium.com/@jackzhang0096/how-to-setup-oauth-2-0-token-strategy-on-feathersjs-1d77cc32118b
With that I think we can close this.
from authentication-oauth2.
Same issue
from authentication-oauth2.
@imdpk @ysfzrn did either of you try my suggestion?
from authentication-oauth2.
You'll need to use this strategy: https://github.com/drudge/passport-facebook-token.
from authentication-oauth2.
I think you actually use the authentication
endpoint with a payload something like this:
{
strategy: 'facebook-token', // or whatever you call it with the `name` options
accessToken: 'the token'
}
Then you should get back a JWT accessToken for your Feathers API.
from authentication-oauth2.
On the server side
1-After adding facebook authentication with feathers-cli, you have to edit config files with your facebook client and your facebook secret
2-In authentication.js, check authentication name,
...
app.configure(
oauth2(
Object.assign(
{
name: "facebook",
Strategy: FacebookStrategy,
},
config.facebook
)
)
);
...
3- If you want to pass more info with your payload, You have to customize JWT payload
app.service("authentication").hooks({
before: {
create: [
authentication.hooks.authenticate(config.strategies),
customizeJWTPayload()
],
remove: [authentication.hooks.authenticate("jwt")]
}
});
};
function customizeJWTPayload() {
return function(hook) {
hook.params.payload = {
facebookId: hook.data.facebookId //facebookId is parameter from client side. We will send
};
return Promise.resolve(hook);
};
}
On the client side
I have to say, I'm using redux saga and I'm calling my functions calling one by one. Of course some of them are async functions and return Promise.
1-Call the LoginManager.logInWithReadPermissions for getting permissions
import { LoginManager} from "react-native-fbsdk";
export function loginWithFacebook(app) {
return new Promise((resolve, reject) => {
LoginManager.logInWithReadPermissions(["public_profile", "email"])
.then(FBloginResult => {
if (FBloginResult.isCancelled) {
throw new Error("Login cancelled");
}
if (FBloginResult.deniedPermissions) {
throw new Error("We need the requested permissions");
}
})
.then(result => {
resolve(result);
})
.catch(error => {
reject(error);
});
});
}
2- After permission accept, get user info from GraphRequestManager.
import {LoginManager,GraphRequest,GraphRequestManager} from "react-native-fbsdk";
const facebookParams = "id,name,email,picture.width(600).height(800)";
export function getUserFacebookInfo(app) {
return new Promise((resolve, reject) => {
const profileInfoCallback = (error, profileInfo) => {
if (error) reject(error);
resolve(profileInfo);
};
const profileInfoRequest = new GraphRequest(
"/me",
{
parameters: {
fields: {
string: facebookParams
}
}
},
profileInfoCallback
);
new GraphRequestManager().addRequest(profileInfoRequest).start();
});
}
3- Ok, now we have permission and user info. Let's authenticate our app
import {LoginManager,GraphRequest,GraphRequestManager,AccessToken} from "react-native-fbsdk";
export function authenticateWithFacebook(app, promiseSuccess, userInfo) {
return app
.authenticate({
strategy: "facebook", // this name must be same with server side name.
accessToken: AccessToken,
facebookId: userInfo.id, // we can pass any parameter what we want for customizing payload
email: userInfo.email,
name: userInfo.name,
image: userInfo.picture.data.url
})
.then(response => {
app.set("token", response.accessToken);
return app.passport.verifyJWT(response.accessToken);
})
.then(payload => {
return app
.service("users")
.find({ query: { facebookId: payload.facebookId } }); //remember we have added this payload on server side
})
.then(user => {
app.set("user", user);
return app.get("token");
});
}
Actually this way, I couldn't authenticate my app . I have doubt about last part. Saving user doesn't seems good. I tried create customVerifier like this but I couldn't.
from authentication-oauth2.
Hi @ysfzrn. I follow your guide but it does not create/update user after authenticate with facebook. Can you please provide an example code?
Updated: I changed to passport-facebook-token and it's working now. Thanks @marshallswain @ekryski
from authentication-oauth2.
Any updates on this?
from authentication-oauth2.
Related Issues (20)
- How to setup a dynamic URL parameters to successRedirect URL HOT 1
- Callback URL problem in production when using oauth HOT 4
- Cannot connect with OAuth2, always getting 404 Not Found Page. HOT 4
- I get Internal server error after I auth with Google authentication HOT 1
- `facebook.profileFields` not works properly HOT 2
- Dependency @feathersjs/express not declared HOT 2
- how to use proxy when call authnetication provider HOT 5
- I got Internal error when I log in with google HOT 1
- JWT Payload is null after app logout HOT 2
- How to pass successUrl from client side? HOT 1
- Deleted
- Confusing in doc of 'OAuth2 Authentication' HOT 2
- Error when save callback payload google login into users service HOT 4
- Restricting certain email domains HOT 1
- Authentication always logging as first user HOT 1
- How to authenticate token from Facebook on Feathers server HOT 3
- JWT sub is always 'anonymous' after using verifier HOT 1
- Cannot use Passport-Google-Token through POST request on /authentication HOT 7
- Entity could be an array? HOT 1
- DefaultVerifier profile id field not configurable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from authentication-oauth2.