Native sign-in / login twitter facebook in iOS


#1

Hi there,

Did anyone achieved a native login in iOS? I don’t mean the web based OAuth but the iOS native one used via cordova plugin.

I wonder if that’s doable in Meteor.

Thanks


#2

Some work in progress here but with ReactNative : https://github.com/spencercarli/react-native-meteor-accounts


#3

@sebastianconcept @lc3t35 here’s a working solution for Twitter:


#4

I’m currently getting that to work. I’m not using Cordova but building directly with Swift. The FBSDKLoginKit directly provides an access token so I had to get that authentication flow to work with Meteor. Here is my code that works: https://gist.github.com/gsabran/8bab053beb05a0a5bf871b4caa00f9b6
You’ll need to use a local version of the facebook package until that my PR is accepted :slight_smile:

I’ve not looked into twitter yet


#5

Hey, so I am trying to get iOS login, and I came across this. Is it plug and play or does it require more?

Cheers!


#6

I’ve not touched that in a while now. But I’m using it just fine with my iOS application, and the PR has been merged. If things don’t look that good, I’d recommend copying the packages of interest from the meteor repo to your local ./packages folder so that meteor uses those instead of its default ones. Then you can start to play with things. Let me know if you have issues, I could spend some time looking. Note that in this gist, I’m using res.respond that is a custom function I made and that you’ll have to adapt to your context.


#7

Thanks I’ll give it a try this weekend. I’ve been trying to solve this issue since May with many others after the 1.3+ update.

If it’s works coffee/beer is on me.


#8

Or if possible, maybe you have a repo I could pull from?


#9

I don’t have a public repo. Here is the code that’s working on my servers:


/*
 * Handle the access token to identify the app with facebook
 * (should do it only once since there don't seem to be an expiration)
 */
let appAccessToken = null;
const getAppAccessToken = () => {
  if (!appAccessToken) {
    try {
      const config = ServiceConfiguration.configurations.findOne({ service: 'facebook' });
      const response = HTTP.get(
        'https://graph.facebook.com/oauth/access_token', {
          params: {
            client_id: config.appId,
            client_secret: OAuth.openSecret(config.secret),
            grant_type: 'client_credentials',
          },
        }).content;
      appAccessToken = response.replace('access_token=', '');
    } catch (e) {
      serverErrorLog('Could not set FB app token' + e);
    }
  }
  return appAccessToken;
};

if (!Meteor.isTest && !Meteor.isAppTest) {
  // in tests, we need to mock this call first
  getAppAccessToken();
}

/*
 * Login with facebook (might create an account)
 */
export const loginWithFacebook = (params, req, res) => {
  const { token: fbAccessToken } = req.body;

  if (!fbAccessToken) {
    return res.respond({ reason: 'Access token is missing' });
  }

  let expiresAt;
  try {
    expiresAt = JSON.parse(HTTP.get('https://graph.facebook.com/debug_token', {
      params: {
        input_token: fbAccessToken,
        access_token: getAppAccessToken(),
      },
    }).content).data.expires_at * 1000;
  } catch (e) {
    return res.respond({ reason: 'fb token is not valid for our app id', status: 401 });
  }

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

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

  res.respond(null, getNewTokensPayloadForUser(userId));
};

getNewTokensPayloadForUser is a custom function


#10

I’ll take the beer :slight_smile:


#11

Hi!

Maybe you can use gillesmanzato:facebook-native-login package for Facebook.

I’m trying to make a similar package for Twitter using twitter-connect-plugin Cordova plugin but I can’t build it for iOS (but works on Android).

Has anyone get to login with Twitter and Blaze on iOS?