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

Expose the function that gets fb data from an access token #7550

Merged
merged 1 commit into from Aug 2, 2016

Conversation

gsabran
Copy link
Contributor

@gsabran gsabran commented Aug 2, 2016

It's possible to get an access token directly, for instance with mobile application. To make it easier to handle those access tokens on the backend, I split the function that handles the token from the larger function that starts with the code.

This enables things like handling fb login directly from an access token:

let fbAppId = null;
export const loginWithFacebook = (params, req, res) => {
  const fbAccessToken = req.body.token;

  // make sure the access token is for our app
  const fbAppIdForToken = JSON.parse(HTTP.get(
    "https://graph.facebook.com/app", {
      params: { access_token: fbAccessToken }
    }).content).id;
  // get our app id
  if (!fbAppId) {
    const config = ServiceConfiguration.configurations.findOne({service: 'facebook'});
    fbAppId = config.appId;
  }
  if (fbAppId !== fbAppIdForToken) {
    // handle incorrect token
    return;
  }

  const expiresAt = req.body.expiresAt;
  const authResult = Facebook.handleAuthFromAccessToken(fbAccessToken, expiresAt);

  const { userId } = Accounts.updateOrCreateUserFromExternalService(
    'facebook',
    authResult.serviceData,
    authResult.options
  );
  ...
};

@apollo-cla
Copy link

@gsabran: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

@gsabran
Copy link
Contributor Author

gsabran commented Aug 2, 2016

@meteor-bot done :)

@tmeasday
Copy link
Contributor

tmeasday commented Aug 2, 2016

Thanks @gsabran, seems reasonable.

@tmeasday tmeasday merged commit 6a79922 into meteor:devel Aug 2, 2016
@tmeasday
Copy link
Contributor

tmeasday commented Aug 2, 2016

@gsabran are you interested in further maintaining the facebook packages? We are looking for maintainers for some of our more peripheral packages.

@gsabran
Copy link
Contributor Author

gsabran commented Aug 2, 2016

I'm happy to contribute when it's easy for me! I'm still the only dev at my startup so I don't have much extra bandwidth. And I'd rather not take responsibilities I can't honor. That being said, I'm happy to contribute as much as I can. So I'd rather not tell you that I'd maintain the package, but I'll try to be helpful.

I'm working on integrating 3rd parties services from mobile clients with a Meteor backend. They (so far for Facebook at least) have flows that differ from web based oauth. I'll make PR when I think it makes sense to bring more flexibility in the accounts packages.

@gsabran gsabran deleted the expose-fb-auth-from-access-token branch August 2, 2016 23:08
@VitalyChe
Copy link

@gsabran Thank you for your commit, I am just looking into authenticating FB/Google the same way as you proposed for mobile apps. What do you think about Google, could it be done the same way?
Thanks

@gsabran
Copy link
Contributor Author

gsabran commented Aug 4, 2016

I haven't look into Google yet, but will probably soon. If that's helpful, here's the full code I'm been using things for Facebook mobile auth in my code: https://gist.github.com/gsabran/8bab053beb05a0a5bf871b4caa00f9b6

@VitalyChe
Copy link

@gsabran Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants