jugem_key 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/jugem_key.gemspec +19 -0
- data/lib/jugem_key.rb +5 -0
- data/lib/jugem_key/auth.rb +98 -0
- data/lib/jugem_key/version.rb +3 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Keisuke KITA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# JugemKey
|
2
|
+
|
3
|
+
A simple interface for using the JugenKey Auththentication API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'jugem_key'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install jugem_key
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'jugem_key'
|
22
|
+
|
23
|
+
api = JugemKey::Auth.new {
|
24
|
+
api_key: '...',
|
25
|
+
secret: '...'
|
26
|
+
}
|
27
|
+
|
28
|
+
# make login uri
|
29
|
+
uri = api.uri_to_login {
|
30
|
+
callback_url: 'http://yourapp_callback_url',
|
31
|
+
params1: 'value1',
|
32
|
+
params2: 'value2'
|
33
|
+
}
|
34
|
+
puts uri
|
35
|
+
|
36
|
+
# exchange frob for token
|
37
|
+
frob = params[:frob]
|
38
|
+
user = api.token(frob) rescue "Couldn't get token"
|
39
|
+
user.name
|
40
|
+
user.token
|
41
|
+
|
42
|
+
# get user info from token
|
43
|
+
user = api.user(token) rescue "Couldn't get user"
|
44
|
+
user.name
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/jugem_key.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jugem_key/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "jugem_key"
|
8
|
+
gem.version = JugemKey::VERSION
|
9
|
+
gem.authors = ["Keisuke KITA"]
|
10
|
+
gem.email = ["kei.kita2501@gmail.com"]
|
11
|
+
gem.description = %q{A simple interface for using the JugenKey Authentication API.}
|
12
|
+
gem.summary = %q{using the JugemKey auth}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/jugem_key.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'cgi'
|
3
|
+
require 'net/http'
|
4
|
+
require 'openssl'
|
5
|
+
require 'rexml/document'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
module JugemKey
|
9
|
+
class Auth
|
10
|
+
JUGEMKEY_URL = 'https://secure.jugemkey.jp'
|
11
|
+
AUTH_API_URL = 'https://api.jugemkey.jp/api/auth'
|
12
|
+
|
13
|
+
def initialize(params)
|
14
|
+
@api_key = params[:api_key]
|
15
|
+
@secret = params[:secret]
|
16
|
+
end
|
17
|
+
|
18
|
+
def uri_to_login(params)
|
19
|
+
sig = api_sig({
|
20
|
+
api_key: @api_key,
|
21
|
+
callback_url: params[:callback_url],
|
22
|
+
perms: "auth"
|
23
|
+
})
|
24
|
+
|
25
|
+
query = {
|
26
|
+
mode: "auth_issue_frob",
|
27
|
+
api_key: @api_key,
|
28
|
+
perms: "auth",
|
29
|
+
api_sig: sig
|
30
|
+
}.merge(params).map { |k, v|
|
31
|
+
k.to_s + "=" + CGI.escape(v)
|
32
|
+
}.join('&')
|
33
|
+
|
34
|
+
URI(JUGEMKEY_URL + '?' + query)
|
35
|
+
end
|
36
|
+
|
37
|
+
def token(frob)
|
38
|
+
sig = api_sig({
|
39
|
+
api_key: @api_key,
|
40
|
+
created: Time.now.iso8601,
|
41
|
+
frob: frob
|
42
|
+
})
|
43
|
+
atom = fetch_atom('http://api.jugemkey.jp/api/auth/token', {
|
44
|
+
"X-JUGEMKEY-API-CREATED" => Time.now.iso8601,
|
45
|
+
"X-JUGEMKEY-API-KEY" => @api_key,
|
46
|
+
"X-JUGEMKEY-API-FROB" => frob,
|
47
|
+
"X-JUGEMKEY-API-SIG" => sig
|
48
|
+
})
|
49
|
+
|
50
|
+
token = REXML::Document.new(atom).elements['entry/token'].text
|
51
|
+
require 'pp'
|
52
|
+
pp token
|
53
|
+
token
|
54
|
+
end
|
55
|
+
|
56
|
+
def user(token)
|
57
|
+
sig = api_sig({
|
58
|
+
api_key: @api_key,
|
59
|
+
created: Time.now.iso8601,
|
60
|
+
token: token
|
61
|
+
})
|
62
|
+
atom = fetch_atom('http://api.jugemkey.jp/api/auth/user', {
|
63
|
+
"X-JUGEMKEY-API-CREATED" => Time.now.iso8601,
|
64
|
+
"X-JUGEMKEY-API-KEY" => @api_key,
|
65
|
+
"X-JUGEMKEY-API-TOKEN" => token,
|
66
|
+
"X-JUGEMKEY-API-SIG" => sig
|
67
|
+
})
|
68
|
+
|
69
|
+
user = REXML::Document.new(atom).elements['entry/title'].text
|
70
|
+
require 'pp'
|
71
|
+
pp user
|
72
|
+
user
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def api_sig(params)
|
77
|
+
value = params.map{|k, v| v}.join('')
|
78
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, @secret, value)
|
79
|
+
end
|
80
|
+
|
81
|
+
def fetch_atom(url, header)
|
82
|
+
Net::HTTP.version_1_2
|
83
|
+
url = URI.parse(url)
|
84
|
+
|
85
|
+
res = nil
|
86
|
+
Net::HTTP.start(url.host, url.port) do |http|
|
87
|
+
res = http.get(url.path, header)
|
88
|
+
end
|
89
|
+
|
90
|
+
if res.class == Net::HTTPOK
|
91
|
+
res.body
|
92
|
+
else
|
93
|
+
raise res.message
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jugem_key
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keisuke KITA
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple interface for using the JugenKey Authentication API.
|
15
|
+
email:
|
16
|
+
- kei.kita2501@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- jugem_key.gemspec
|
27
|
+
- lib/jugem_key.rb
|
28
|
+
- lib/jugem_key/auth.rb
|
29
|
+
- lib/jugem_key/version.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.23
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: using the JugemKey auth
|
54
|
+
test_files: []
|