app/controllers/v1/users/sessions_controller.rb
###
#
# Gets a code from the frontend application and verifies that the code correspond to a user.
#
# * If the user does exist, it gets updated.
# * If the user does not exist, it gets created.
#
# @param code [String] Code received from the front-end for authentication
# @return user [User]
# @return token [String]
#
Gets a code from the frontend application and verifies that the code correspond to a user.
If the user does exist, it gets updated.
If the user does not exist, it gets created.
Gets a code from the frontend application and verifies that the code correspond to a user . If the user does exist it gets updated . If the user does not exist it gets created .
def verify_user!(code, provider, request)
        logger.debug 'Verifying that the user code is valid and authenticating user'
        pr = Providers::BaseManager.new(nil)
        validate_provider = pr.validate_provider(provider)
        return  validate_provider if validate_provider.kind_of? ErrorExchange
        connector = pr.get_connector
        access_token = code ? connector.exchange_code_for_token!(code) : nil 
        raise Octokit::NotFound unless access_token[:error].nil?
        github_user = connector.user
        raise Octokit::Unauthorized if github_user.nil?
        logger.debug "Valid code, finding or creating user #{github_user.login}"
        user = User.return_user(github_user)
        logger.debug 'Creating user session token'
        token = Tiddle.create_and_return_token(user, request)
        authentication_token = Tiddle::TokenIssuer.build.find_token(user, token)
        authentication_token.update(github_token: access_token[:access_token], provider: provider)
        [user, token]
      end
def verify_user! ( code , provider , request ) logger . debug 'Verifying that the user code is valid and authenticating user' pr = Providers :: BaseManager . new ( nil ) validate_provider = pr . validate_provider ( provider ) return validate_provider if validate_provider . kind_of? ErrorExchange connector = pr . get_connector access_token = code ? connector . exchange_code_for_token! ( code ) : nil raise Octokit :: NotFound unless access_token [ :error ] . nil? github_user = connector . user raise Octokit :: Unauthorized if github_user . nil? logger . debug "Valid code, finding or creating user #{github_user.login}" user = User . return_user ( github_user ) logger . debug 'Creating user session token' token = Tiddle . create_and_return_token ( user , request ) authentication_token = Tiddle :: TokenIssuer . build . find_token ( user , token ) authentication_token . update ( github_token : access_token [ :access_token ] , provider : provider ) [ user , token ] end
Gets a code from the frontend application and verifies that the code correspond to a user.
Gets a code from the frontend application and verifies that the code correspond to a user .
# Verify github code and get token with it
None
User
None
String
code
Code received from the front-end for authentication
Code received from the front - end for authentication
provider
request