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

feat: add facebook driver #121

Merged
merged 5 commits into from
Jun 8, 2021
Merged

feat: add facebook driver #121

merged 5 commits into from
Jun 8, 2021

Conversation

irwing-reza
Copy link
Contributor

@irwing-reza irwing-reza commented Jun 4, 2021

Proposed changes

Add Facebook diver

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [x ] I have read the CONTRIBUTING doc
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@thetutlage
Copy link
Member

Looks great. Can you please rebase your branch with the latest develop branch, as there are merge conflicts in your PR?

@irwing-reza
Copy link
Contributor Author

Branch has been updated.

protected accessTokenUrl = 'https://graph.facebook.com/v10.0/oauth/access_token'
protected authorizeUrl = 'https://www.facebook.com/v10.0/dialog/oauth'
protected graphUrl = 'https://graph.facebook.com'
protected graphVersion = 'v10.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need separate graphUrl and graphVersion variables. We can just hardcode them inside the userInfoUrl coz the user can overwrite the entire URL anyways

* Define params based upon user config
*/
if (this.config.popup) {
request.param('display', this.config.reRequest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be this.config.display

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed and changed to use the param name on config.

* Send state to Facebook when request is not stateles
*/
if (!this.isStateless) {
request.field('state', this.stateCookieValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does facebook access token request accepts state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the facebook documentation it should.

state. A string value created by your app to maintain state between the request and callback. This parameter should be used for preventing Cross-site Request Forgery and will be passed back to you, unchanged, in your redirect URI.
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/#logindialog

Copy link
Member

@thetutlage thetutlage Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are passing it to the access token request (not the redirect request).

Screen Shot 2021-06-08 at 7 23 43 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, removed this

protected async getUserInfo(token: string, callback?: (request: ApiRequestContract) => void) {
const fields = this.config.userFields || this.userFields
const fieldList = fields.join(',')
const requestUrl = `${this.graphUrl}/${this.config.graphVersion || this.graphVersion}/me`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using the this.config.userInfoUrl || this.userInfoUrl property here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


Route.get('/facebook/redirect', async ({ ally }) => {
return ally.use('facebook').redirect((request) => {
request.scopes(['user', 'repo'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this example to use facebook scopes?

'last_name',
'link',
'email',
// 'picture',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please uncomment the picture field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncommented

@thetutlage thetutlage merged commit a9493f2 into adonisjs:develop Jun 8, 2021
@thetutlage
Copy link
Member

Looks great. Thanks for taking out the time to contribute 🙂

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.

2 participants