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



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/omniauth/strategies/blockstack.rb', line 74

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
63
64
65
66
67
68
69
70
71
72
# 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 = "  var manifestURI = \"\#{callback_url.chomp(\"/callback\") + \"?manifest=true\"}\"\n  var redirectURI = \"\#{callback_url}\"\n\n  JAVASCRIPT\n\n  header_info << \"<script>\#{app_data_js}</script>\"\n  header_info << \"<script>\#{auth_request_js}</script>\"\n\n  title = \"Redirecting to Blockstack\"\n  html << <<-HTML\n    <!DOCTYPE html>\n    <html>\n    <head>\n      <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n      <title>\#{title}</title>\n      \#{header_info}\n    </head>\n    <body>Redirecting to blockstack</body>\n    </html>\n  HTML\n  Rack::Response.new(html, 200, 'content-type' => 'text/html').finish\nend\n"