omniauth-indieauth 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ require 'omniauth'
2
+ require 'faraday'
3
+ require 'cgi'
4
+ require 'microformats2'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class IndieAuth
9
+ include OmniAuth::Strategy
10
+
11
+ option :name, 'indieauth'
12
+ option :server, 'https://indieauth.com'
13
+ option :client_id
14
+
15
+ attr_accessor :me
16
+
17
+ def redirect_uri
18
+ full_host + script_name + callback_path
19
+ end
20
+
21
+ def request_phase
22
+ puts redirect_uri
23
+ redirect "#{options.server}/sign-in?redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&client_id=#{URI.encode_www_form_component(options.client_id)}"
24
+ end
25
+
26
+ def callback_phase
27
+ puts request.params.inspect
28
+
29
+ conn = Faraday.new(:url => "#{options.server}/auth") do |faraday|
30
+ faraday.request :url_encoded # form-encode POST params
31
+ end
32
+ response = Faraday.post "#{options.server}/auth", {
33
+ :code => request.params['code'],
34
+ :client_id => options.client_id,
35
+ :redirect_uri => redirect_uri
36
+ }
37
+ puts response.body
38
+
39
+ data = CGI::parse response.body
40
+
41
+ if data['me'].length > 0
42
+ @me = data['me'][0]
43
+ else
44
+ fail!(data['error'][0].to_sym, CallbackError.new(data['error'][0].to_sym, data['error_description'][0]))
45
+ end
46
+
47
+ super
48
+ end
49
+
50
+ uid do
51
+ @me
52
+ end
53
+
54
+ info do
55
+ data = {
56
+ :url => @me,
57
+ :name => @me.gsub(/https?:\/\//, '')
58
+ }
59
+
60
+ # Parse the url and look for an h-card to fill out the profile info
61
+ begin
62
+ src = Faraday.get @me
63
+ m = Microformats2.parse src.body
64
+
65
+ if m.card
66
+ data[:name] = m.card.name.to_s if m.card.name
67
+ data[:image] = m.card.photo.to_s if m.card.photo
68
+ end
69
+ rescue
70
+ # Ignore errors
71
+ end
72
+
73
+ data
74
+ end
75
+
76
+ class CallbackError < StandardError
77
+ attr_accessor :error, :error_reason, :error_uri
78
+
79
+ def initialize(error, error_reason = nil, error_uri = nil)
80
+ self.error = error
81
+ self.error_reason = error_reason
82
+ self.error_uri = error_uri
83
+ end
84
+
85
+ def message
86
+ [error, error_reason, error_uri].compact.join(' | ')
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ end
93
+
94
+ OmniAuth.config.add_camelization 'indieauth', 'IndieAuth'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module IndieAuth
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require '../lib/omniauth-indieauth/version'
2
+ require '../lib/omniauth/strategies/indieauth'
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-indieauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Parecki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: microformats2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.1
30
+ description: IndieAuth adapter for OmniAuth
31
+ email:
32
+ - aaron@parecki.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/omniauth-indieauth.rb
38
+ - lib/omniauth/strategies/indieauth.rb
39
+ - lib/omniauth-indieauth/version.rb
40
+ homepage: https://github.com/aaronpk/omniauth-indieauth
41
+ licenses:
42
+ - Apache 2.0
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: IndieAuth adapter for OmniAuth
65
+ test_files: []