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

Facebook OAuth Implementation #1026

Open
detrohutt opened this issue Jul 22, 2020 · 1 comment
Open

Facebook OAuth Implementation #1026

detrohutt opened this issue Jul 22, 2020 · 1 comment

Comments

@detrohutt
Copy link

detrohutt commented Jul 22, 2020

Feature request

Is your feature request related to a problem? Please describe.

I'd really rather not use password auth and all the prospective users of my app will be acquired through Facebook so I'd prefer to make signing up simple for them.

Describe the solution you'd like

I believe I can use the oauth-twitter package in this project as a guide to creating a similar oauth-facebook package. I just want to make sure you are open to merging it if I am successful. I have read the contributing guide and plan to provide tests similar to those for Twitter.

Thanks for your time. :)

@agustif
Copy link
Contributor

agustif commented Jul 22, 2020

I've this developed and working, willl try to add an example later here !
oauth-facebook/src/accounts-oauth-facebook.ts

import * as oauth from 'oauth';

import { Configuration } from './types/configuration';
//
export class AccountsOAuthFacebook {
  private config: Configuration;
  private oauth: any;

  constructor(config: Configuration) {
    this.config = config;
    this.oauth = new oauth.OAuth(
      'https://graph.facebook.com/oauth/access_token',
      this.config.key,
      this.config.secret
    );
  }

  public authenticate(params: any) {
    return new Promise((resolve, reject) => {
      this.oauth.get(
        'https://graph.facebook.com/me?access_token=',
        params.access_token,
        params.access_token_secret,
        (err: any, data: any) => {
          if (err) {
            reject(err);
          } else {
            data = JSON.parse(data);
            const user = {
              id: data.id_str,
              screenName: data.screen_name,
              profilePicture: data.profile_image_url_https,
              email: data.email,
              accessToken: params.access_token,
              accessTokenSecret: params.access_token_secret,
            };
            resolve(user);
          }
        }
      );
    });
  }
}

index.ts

import { AccountsOAuthFacebook } from './accounts-oauth-twitter';

export default AccountsOAuthFacebook;

types.configuration.ts

export interface Configuration {
  key: string;
  secret: string;
}

that's just the faceebook-package.

will open a PR lateer with it and a full frontend example (hopefully)

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

No branches or pull requests

2 participants