-
Notifications
You must be signed in to change notification settings - Fork 282
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 OAUTH Login #245
base: master
Are you sure you want to change the base?
API for OAUTH Login #245
Conversation
poudelprakash
commented
Nov 19, 2020
•
edited
Loading
edited
- Add route and api controller
- Return access token for omniauth_token
* api-for-facebook-login: - Add route and api controller - Return access token for omniauth_token
namespace :api, defaults: { format: 'json' } do | ||
namespace :v1 do | ||
devise_scope :spree_user do | ||
post '/spree_oauth/social_login/:provider', to: 'omniauth_callbacks#login' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [82/80]
eligible_providers = SpreeSocial::OAUTH_PROVIDERS.map { |provider| provider[1] if provider[2] == 'true' }.compact | ||
|
||
unless eligible_providers.include?(auth_hash['provider']) | ||
render json: { error: I18n.t('devise.omniauth_callbacks.provider_not_found', kind: auth_hash['provider']) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [114/80]
def validate_provider | ||
eligible_providers = SpreeSocial::OAUTH_PROVIDERS.map { |provider| provider[1] if provider[2] == 'true' }.compact | ||
|
||
unless eligible_providers.include?(auth_hash['provider']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/GuardClause: Use a guard clause instead of wrapping the code inside a conditional expression.
end | ||
|
||
def validate_provider | ||
eligible_providers = SpreeSocial::OAUTH_PROVIDERS.map { |provider| provider[1] if provider[2] == 'true' }.compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [117/80]
resource_owner_id: user.id, | ||
expires_in: Doorkeeper.configuration.access_token_expires_in, | ||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled? | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
spree_current_user.save! | ||
access_token(spree_current_user) | ||
else | ||
user = Spree::User.find_by_email(auth_hash['info']['email']) || Spree::User.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [85/80]
before_action :validate_provider, only: :login | ||
|
||
def login | ||
authentication = Spree::UserAuthentication.find_by_provider_and_uid(auth_hash['provider'], auth_hash['uid']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [112/80]
skip_before_action :verify_authenticity_token | ||
before_action :validate_provider, only: :login | ||
|
||
def login |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for login is too high. [32.62/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for login is too high. [7/6]
Metrics/MethodLength: Method has too many lines. [17/10]
Metrics/PerceivedComplexity: Perceived complexity for login is too high. [9/7]
@@ -0,0 +1,48 @@ | |||
class Spree::Api::V1::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
@@ -0,0 +1,48 @@ | |||
class Spree::Api::V1::OmniauthCallbacksController < Devise::OmniauthCallbacksController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/Documentation: Missing top-level class documentation comment.
Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
Style/ClassAndModuleChildren: Use nested module/class definitions instead of compact style.
Metrics/LineLength: Line is too long. [87/80]