-
Notifications
You must be signed in to change notification settings - Fork 281
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
Added api exposure for logging in with an oauth access token. #237
base: 3-1-stable
Are you sure you want to change the base?
Conversation
end | ||
end | ||
|
||
Spree::Api::V1::UsersController.prepend(Spree::Api::V1::UsersControllerDecorator) |
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. [81/80]
Layout/TrailingBlankLines: Final newline missing.
:user_id => "#{user.id}" | ||
}} | ||
end | ||
|
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/EmptyLinesAroundModuleBody: Extra empty line detected at module body end.
:user => "#{user.login}", | ||
:api_key => "#{user.spree_api_key}", | ||
:user_id => "#{user.id}" | ||
}} |
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/SpaceInsideHashLiteralBraces: Space inside } missing.
render :json => {:result => { | ||
:user => "#{user.login}", | ||
:api_key => "#{user.spree_api_key}", | ||
:user_id => "#{user.id}" |
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/HashSyntax: Use the new Ruby 1.9 hash syntax.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
def render_user_login(user) | ||
render :json => {:result => { | ||
:user => "#{user.login}", | ||
:api_key => "#{user.spree_api_key}", |
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/HashSyntax: Use the new Ruby 1.9 hash syntax.
Style/UnneededInterpolation: Prefer to_s over string interpolation.
else | ||
user = Spree::User.find_by_email(params[:email]) || Spree::User.new | ||
user.apply_omniauth(omniauth_hash) | ||
if user.save! |
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/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
omniauth_hash = authentication_method.get_omniauth_hash(params[:oauth_token]) | ||
authentication = Spree::UserAuthentication.find_by_provider_and_uid(params[:provider], omniauth_hash['uid']) | ||
|
||
if authentication.present? and authentication.try(:user).present? |
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/AndOr: Use && instead of and.
authentication_method = Spree::AuthenticationMethod.find_by_provider(params[:provider]) | ||
render json: {exception: 'Unsupported provider'}, status: 422 and return unless authentication_method | ||
omniauth_hash = authentication_method.get_omniauth_hash(params[:oauth_token]) | ||
authentication = Spree::UserAuthentication.find_by_provider_and_uid(params[:provider], omniauth_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. [118/80]
def social_login | ||
authentication_method = Spree::AuthenticationMethod.find_by_provider(params[:provider]) | ||
render json: {exception: 'Unsupported provider'}, status: 422 and return unless authentication_method | ||
omniauth_hash = authentication_method.get_omniauth_hash(params[:oauth_token]) |
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. [87/80]
|
||
def social_login | ||
authentication_method = Spree::AuthenticationMethod.find_by_provider(params[:provider]) | ||
render json: {exception: 'Unsupported provider'}, status: 422 and return unless authentication_method |
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/SpaceInsideHashLiteralBraces: Space inside { missing.
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
Style/AndOr: Use && instead of and.
Metrics/LineLength: Line is too long. [111/80]
…ut use safe_constantize instead
…the api key in their SDK
def oauth_providers | ||
user_authentications.map do |user_authentication| | ||
{ | ||
provider: user_authentication.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.
Layout/IndentHash: Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
def strategy(token) | ||
app = lambda {|env| [200, {}, ["Hello World."]]} | ||
options = [api_key, api_secret] | ||
strategy_class.new(app, *options).tap {|s| s.access_token = access_token(token)} |
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/SpaceInsideBlockBraces: Space between { and | missing.
Metrics/LineLength: Line is too long. [84/80]
Layout/SpaceInsideBlockBraces: Space missing inside }.
end | ||
|
||
def strategy(token) | ||
app = lambda {|env| [200, {}, ["Hello World."]]} |
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/Lambda: Use the -> { ... } lambda literal syntax for single line lambdas.
Layout/SpaceInsideBlockBraces: Space between { and | missing.
Lint/UnusedBlockArgument: Unused block argument - env. If it's necessary, use _ or _env as an argument name to indicate that it won't be used. Also consider using a proc without arguments instead of a lambda if you want it to accept any arguments but don't care about them.
Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Layout/SpaceInsideBlockBraces: Space missing inside }.
end | ||
|
||
def client | ||
::OAuth2::Client.new(api_key, api_secret, strategy_class.default_options.client_options.to_h).tap do |c| |
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. [108/80]
end | ||
|
||
def provider_must_be_backed_by_omniauth_strategy | ||
errors.add(:provider, 'must be backed by an omniauth strategy') unless strategy_class.safe_constantize |
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. [106/80]
module UsersControllerDecorator | ||
|
||
def social_login | ||
authentication_method = Spree::AuthenticationMethod.find_by_provider(params[: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. [97/80]
module V1 | ||
module UsersControllerDecorator | ||
|
||
def social_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 social_login is too high. [32.95/15]
Metrics/CyclomaticComplexity: Cyclomatic complexity for social_login is too high. [11/6]
Metrics/MethodLength: Method has too many lines. [22/10]
Metrics/PerceivedComplexity: Perceived complexity for social_login is too high. [12/7]
module Api | ||
module V1 | ||
module UsersControllerDecorator | ||
|
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/EmptyLinesAroundModuleBody: Extra empty line detected at module body beginning.
module Spree | ||
module Api | ||
module V1 | ||
module UsersControllerDecorator |
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 module documentation comment.
@@ -0,0 +1,64 @@ | |||
module Spree |
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/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.
Is this repo still active? |
This PR adds the option to use a valid access token to authenticate with the application.
The omniauth strategies are used for the authentication but obtaining a token part is skipped. Instead, the token is directly fed to the strategy and the user info is retrieved via the strategy.
This feature would allow any API consumer with a valid token to register or login using this token.
Could not test since they seem broken on 3-1-stable. Is anybody else experiencing problems running the tests?
getting an
undefined method 'load_defaults' for #<Rails::Application::Configuration:0x00007f8673c52e60>
error