omniauth-figshare 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
= omniauth-figshare
|
2
|
+
|
3
|
+
* https://github.com/jdleesmiller/omniauth-figshare
|
4
|
+
|
5
|
+
An OmniAuth Strategy for the figshare API. You can use it to authenticate users
|
6
|
+
against the figshare API in your ruby on rails / sinatra / other rack-based web
|
7
|
+
application.
|
8
|
+
|
9
|
+
=== Usage
|
10
|
+
|
11
|
+
Add this strategy to your Gemfile:
|
12
|
+
|
13
|
+
gem 'omniauth-figshare'
|
14
|
+
|
15
|
+
Then add the strategy as Rack middleware. In rails, you can add an initializer
|
16
|
+
+config/initializers/omniauth.rb+ containing
|
17
|
+
|
18
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
19
|
+
provider :figshare,
|
20
|
+
ENV['FIGSHARE_CONSUMER_KEY'],
|
21
|
+
ENV['FIGSHARE_CONSUMER_SECRET'],
|
22
|
+
end
|
23
|
+
|
24
|
+
where the consumer key and secret are obtained from your figshare app's
|
25
|
+
settings and stored in environmental variables.
|
26
|
+
|
27
|
+
Then create routes
|
28
|
+
|
29
|
+
match '/auth/figshare/callback', to: 'authentications#create'
|
30
|
+
match '/auth/failure', to: 'authentications#failure'
|
31
|
+
|
32
|
+
and an +AuthenticationController+ to handle the postback from figshare upon
|
33
|
+
successful (or failed) authentication:
|
34
|
+
|
35
|
+
class AuthenticationsController < ApplicationController
|
36
|
+
#
|
37
|
+
# We use this only to connect oauth accounts to existing wL accounts, at
|
38
|
+
# present.
|
39
|
+
#
|
40
|
+
def create
|
41
|
+
auth = env["omniauth.auth"]
|
42
|
+
# ...
|
43
|
+
# You should store
|
44
|
+
# auth.credentials.token
|
45
|
+
# auth.credentials.secret
|
46
|
+
# for future authentication against the figshare API. auth[:uid] is the
|
47
|
+
# user's figshare user id.
|
48
|
+
#
|
49
|
+
# hint: check env['omniauth.origin'] to redirect the user to wherever they
|
50
|
+
# were trying to get to before connecting
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
For more information, see
|
55
|
+
|
56
|
+
* https://github.com/intridea/omniauth/wiki -- the official OmniAuth docs
|
57
|
+
* http://railscasts.com/episodes/241-simple-omniauth -- for background
|
58
|
+
* http://railscasts.com/episodes/235-omniauth-part-1 -- for integration with devise
|
59
|
+
* http://railscasts.com/episodes/235-omniauth-part-2 -- for integration with devise
|
60
|
+
|
61
|
+
=== Notes
|
62
|
+
|
63
|
+
Figshare supports OAuth 1.0, so this is just a light wrapper over the standard
|
64
|
+
OmniAuth OAuth strategy.
|
65
|
+
|
66
|
+
This is an extraction from writeLaTeX, the online scientific writing platform
|
67
|
+
(www.writelatex.com).
|
68
|
+
|
69
|
+
== LICENSE
|
70
|
+
|
71
|
+
(The MIT License)
|
72
|
+
|
73
|
+
Copyright (c) 2013 John Lees-Miller
|
74
|
+
|
75
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
76
|
+
a copy of this software and associated documentation files (the
|
77
|
+
'Software'), to deal in the Software without restriction, including
|
78
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
79
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
80
|
+
permit persons to whom the Software is furnished to do so, subject to
|
81
|
+
the following conditions:
|
82
|
+
|
83
|
+
The above copyright notice and this permission notice shall be
|
84
|
+
included in all copies or substantial portions of the Software.
|
85
|
+
|
86
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
87
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
88
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
89
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
90
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
91
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
92
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
93
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'omniauth-oauth'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Fix a minor non-conformity in the figshare API: from request_token, it should
|
5
|
+
# return
|
6
|
+
# oauth_callback_confirmed=true
|
7
|
+
# (small t on true) but it returns
|
8
|
+
# oauth_callback_confirmed=True
|
9
|
+
# (big T on True). This is enough to cause omniauth-oauth not to pass the
|
10
|
+
# oauth_verifier back to access_token, which breaks authentication.
|
11
|
+
#
|
12
|
+
module OAuth
|
13
|
+
class RequestToken
|
14
|
+
def figshare_callback_confirmed?
|
15
|
+
params[:oauth_callback_confirmed].casecmp("true") == 0
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :original_callback_confirmed?, :callback_confirmed?
|
19
|
+
alias_method :callback_confirmed?, :figshare_callback_confirmed?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module OmniAuth
|
24
|
+
module Strategies
|
25
|
+
class Figshare < OmniAuth::Strategies::OAuth
|
26
|
+
option :name, 'figshare'
|
27
|
+
|
28
|
+
option :client_options, {
|
29
|
+
:site => 'http://api.figshare.com/v1/pbl'
|
30
|
+
}
|
31
|
+
|
32
|
+
uid {
|
33
|
+
access_token.params['xoauth_figshare_id']
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-figshare
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Lees-Miller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.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: 1.0.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.6.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: gemma
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
description: An OmniAuth Strategy for the figshare API. You can use it to authenticate
|
63
|
+
users against the figshare API in your ruby on rails / sinatra / other rack-based
|
64
|
+
web application.
|
65
|
+
email:
|
66
|
+
- jdleesmiller
|
67
|
+
executables: []
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files:
|
70
|
+
- README.rdoc
|
71
|
+
files:
|
72
|
+
- lib/omniauth-figshare/version.rb
|
73
|
+
- lib/omniauth-figshare.rb
|
74
|
+
- lib/omniauth/strategies/figshare.rb
|
75
|
+
- README.rdoc
|
76
|
+
- test/omniauth-figshare/omniauth-figshare_test.rb
|
77
|
+
homepage: https://github.com/jdleesmiller
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --main
|
82
|
+
- README.rdoc
|
83
|
+
- --title
|
84
|
+
- omniauth-figshare-0.0.1 Documentation
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: -805240337
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: -805240337
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project: omniauth-figshare
|
107
|
+
rubygems_version: 1.8.25
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: An OmniAuth strategy for the figshare API.
|
111
|
+
test_files:
|
112
|
+
- test/omniauth-figshare/omniauth-figshare_test.rb
|
113
|
+
has_rdoc:
|