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

API for social login #1

Merged
merged 5 commits into from
Oct 11, 2020
Merged

API for social login #1

merged 5 commits into from
Oct 11, 2020

Conversation

shradhaN
Copy link

@shradhaN shradhaN commented Sep 29, 2020

API endpoint: {base_url}/v1/spree_oauth/social_login/:provider
method: POST

Request Body:

  "provider": "facebook",
  "uid": "3329220777170562",
  "info": {
    "email": "[email protected]",
    "name": "Example Example",
    "image": "http://graph.facebook.com/v4.0/3329220777170562/picture"
  },
  "credentials": {
    "token": "<token>",
    "expires_at": 1606145485,
    "expires": true
  },
  "extra": {
    "raw_info": {
      "email": "[email protected]",
      "name": "Example Example",
      "id": "3329220777170562"
    }
  }
}

Response Body:

{
    "access_token": "F7eVY71qJdIVVsZ-MmuZ1VXtSBGoI6Gsdoac3hrPAyg",
    "token_type": "Bearer",
    "expires_in": 7200,
    "refresh_token": "eGp3TPP4RyJD2jJG02KL-i7yl1Y90wbbpNSoYXyTcks",
    "created_at": 1601391609
}

include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::Auth
include Spree::Core::ControllerHelpers::Store

Choose a reason for hiding this comment

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

do we need all of these modules?

skip_before_action :verify_authenticity_token

def login
eligible_providers = SpreeSocial::OAUTH_PROVIDERS.map { |p| p[1] if p[2] == 'true' }.compact

Choose a reason for hiding this comment

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

isn't there any helper method for this available yet? does not look like it really belongs to login method

Choose a reason for hiding this comment

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

Would it make sense to use more sensible variable names instead of p?

eligible_providers = SpreeSocial::OAUTH_PROVIDERS.map { |p| p[1] if p[2] == 'true' }.compact

if !(eligible_providers.include?(auth_hash['provider']))
render json: {error: I18n.t('devise.omniauth_callbacks.provider_not_found', kind: auth_hash['provider'])}, status: :unprocessable_entity

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

we should be able to just raise error and base controller should be able to handle the exceptions..
we have lots of things going inside this action

config/routes.rb Outdated
end
end
end

Choose a reason for hiding this comment

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

last line missing

@poudelprakash
Copy link

@shradhaN you have sensitive information in above description,
please modify json to hide sensitive information..

We have checked this change and is working for us, you can create pr in spree-contrib's repo as well.
I am merging this for us :D

Thank you

@poudelprakash poudelprakash merged commit 0af46da into master Oct 11, 2020
@poudelprakash
Copy link

we will also need documentation in repo for this :D

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.

3 participants