Class: OmniAuth::Strategies::Blockstack

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/blockstack.rb

Defined Under Namespace

Classes: ClaimInvalid

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/omniauth/strategies/blockstack.rb', line 64

def callback_phase
  auth_response = request.params['authResponse']

  ::Blockstack.api = options.blockstack_api
  ::Blockstack.leeway = options.leeway
  ::Blockstack.valid_within = options.valid_within
  @decoded_token = ::Blockstack.verify_auth_response auth_response

  super

rescue ::Blockstack::InvalidAuthResponse => error
  fail! :invalid_auth_response, error
end

#decoded_tokenObject



23
24
25
# File 'lib/omniauth/strategies/blockstack.rb', line 23

def decoded_token
  @decoded_token
end

#request_phaseObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/omniauth/strategies/blockstack.rb', line 27

def request_phase
  app_manifest = {
    :name => options.app_name,
    :short_name => (options.app_short_name ? options.app_short_name : options.app_name),
    :start_url => callback_url,
    :display => "standalone",
    :background_color => "#fff",
    :description => options.app_description,
    :icons => options.app_icons
  }

  if request.params["manifest"]
    return Rack::Response.new(app_manifest.to_json,
                              200,
                              'content-type' => 'text/json',
                              'Access-Control-Allow-Origin' => '*').finish
  end

  blockstack_js = File.open(File.join(File.dirname(__FILE__), "blockstack.js"), "rb").read

  auth_request_js = File.open(File.join(File.dirname(__FILE__), "auth-request.js"), "rb").read

  header_info = "<script>#{blockstack_js}</script>"
  app_data_js = <<~JAVASCRIPT
  var manifestURI = "#{callback_url.chomp("/callback") + "?manifest=true"}"
  var redirectURI = "#{callback_url}"

  JAVASCRIPT

  header_info << "<script>#{app_data_js}</script>"
  header_info << "<script>#{auth_request_js}</script>"
  form = OmniAuth::Form.new(:title => "Blockstack Auth Request Generator",
  :header_info => header_info,
  :url => callback_path)
  form.to_response
end