docs
docs copied to clipboard
Cookbook Suggestion:
It took me a great deal of time to get Google& FB auth working over Apache ProxyReverse using a specific URL path. its pretty simple to do. I believe we need a recipe for it, as others are sure to find it useful as well. The idea is to be able to run multiple feathers apps using different ports all being served by the 443 port.
in other words, we could have something like:
https://DOMAIN.com/myAppOne/ -- ProxyReverse over port 3030 https://DOMAIN.com/myAppTwo -- ProxyReverse over port 3050
./var/httpd/conf/httpd.conf:
<Location /feathers/> ProxyPass http://localhost:3030/ ProxyPassReverse http://localhost:3030/ </Location>
./config/default.json:
{ "host": "FEATHERSTEST.WEBSITE", ............................................ "oauth": { "redirect" : "/feathers/", "defaults" : { "protocol" : "https" }, "facebook": { "key": "5XXXXXXXXXXXX4", "secret": "7XXXXXXXXXXXXXXXXXXXXXX8a", "scope": ["public_profile, email"], "redirect_uri": "https://FEATHERSTEST.WEBSITE/feathers/oauth/connect/facebook/callback", "callback": "https://FEATHERSTEST.WEBSITE/feathers/oauth/facebook/authenticate" }, "google": { "key": "8XXXXXXXXXXXXXXXXXXXXXXi.apps.googleusercontent.com", "secret": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXi", "redirect_uri": "https://FEATHERSTEST.WEBSITE/feathers/oauth/connect/google/callback", "callback": "https://FEATHERSTEST.WEBSITE/feathers/oauth/google/authenticate", "scope": [ "email", "profile", "openid" ] } }
index.html:
var socket = io( { transports: [ 'polling' ] , path: window.location.pathname +'socket.io' });
var feathersClient = feathers() //.configure(feathers.hooks()) commented out with 3.0 .configure(feathers.socketio(socket)) .configure(feathers.authentication({ cookie: 'feathers-jwt' }));
feathersClient.authenticate() .then(response => { console.info('Feathers Client has Authenticated with the JWT access token!'); console.log(response); }) .catch(error => { console.info("We have not logged in with OAuth, yet. This means there's no cookie storing the accessToken. As a result, feathersClient.authenticate() failed."); console.log(error); });
facebook google <a href='#' onClick='javascript: (async () => { await feathersClient.logout(); })(); '>logout
./src/authentication.js :
const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication'); const { LocalStrategy } = require('@feathersjs/authentication-local'); const { expressOauth, OAuthStrategy } = require('@feathersjs/authentication-oauth');
const axios = require('axios');
class FacebookStrategy extends OAuthStrategy { async getProfile (authResult) {
const accessToken = authResult.access_token;
const { data } = await axios.get('https://graph.facebook.com/me', {
headers: {
authorization: `Bearer ${accessToken}`
},
params: {
fields: 'id,name,email,picture'
}
});
return data;
}
async getEntityData(profile) {
const baseData = await super.getEntityData(profile);
return {
...baseData,
name: profile.name,
email: profile.email
};
} }
class GoogleStrategy extends OAuthStrategy { async getEntityData(profile) {
const baseData = await super.getEntityData(profile);
return {
...baseData,
profilePicture: profile.picture,
email: profile.email
};
} }
module.exports = app => { const authentication = new AuthenticationService(app);
authentication.register('jwt', new JWTStrategy()); authentication.register('local', new LocalStrategy()); authentication.register('facebook', new FacebookStrategy()); authentication.register('google', new GoogleStrategy());
app.use('/authentication', authentication); app.configure(expressOauth()); };
https://github.com/feathersjs/docs/pull/1379
not sure why this was closed...?