Class: Warden::GitHub::Strategy

Inherits:
Strategies::Base
  • Object
show all
Defined in:
lib/warden/github/strategy.rb

Constant Summary collapse

SESSION_KEY =
'warden.github.oauth'

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

The first time this is called, the flow gets set up, stored in the session and the user gets redirected to GitHub to perform the login.

When this is called a second time, the flow gets evaluated, the code gets exchanged for a token, and the user gets loaded and passed to warden.

If anything goes wrong, the flow is aborted and reset, and warden gets notified about the failure.

Once the user gets set, warden invokes the after_authentication callback that handles the redirect to the originally requested url and cleans up the flow. Note that this is done in a hook because setting a user (through #success!) and redirecting (through #redirect!) inside the #authenticate! method are mutual exclusive.



21
22
23
24
25
26
27
# File 'lib/warden/github/strategy.rb', line 21

def authenticate!
  if in_flow?
    continue_flow!
  else
    begin_flow!
  end
end

#finalize_flow!Object

This is called by the after_authentication hook which is invoked after invoking #success!.



37
38
39
40
41
# File 'lib/warden/github/strategy.rb', line 37

def finalize_flow!
  redirect!(custom_session['return_to'])
  teardown_flow
  throw(:warden)
end

#in_flow?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/warden/github/strategy.rb', line 29

def in_flow?
  !custom_session.empty? &&
    params['state'] &&
    (params['code'] || params['error'])
end