ghoa 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +1 -0
- data/.gitignore +1 -0
- data/LICENSE +19 -0
- data/README.md +60 -0
- data/ghoa.gemspec +15 -0
- data/lib/ghoa.rb +33 -0
- data/test/app.rb +29 -0
- data/test/config.ru +3 -0
- data/test/makefile +4 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fad4bd0493bd8784480d79ebe06ba877bf66868
|
4
|
+
data.tar.gz: 6b9249806f0d863a91824a1440a8724c89e21165
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65babfc7b70a25b777cf3abb5786854c5f083d6c149209dca647ab7de8c8d410f36e41b00b43654b3310efdd4fc54a56bd576ab260866c49b9eb3fcde956f2d2
|
7
|
+
data.tar.gz: 3fca15f3a187b0f92d08cc474dfaca3edd0f5887f2857352aae009ce6055120db343713c389a6bf313d7f605186d52c6ddfa0516625dab850f399d3c69192387
|
data/.gems
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
cuba -v 3.2.0
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.DS_Store
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Punchgirls LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#Ghoa
|
2
|
+
|
3
|
+
A gem for hazzle-free GitHub authentication and retrival of user information.
|
4
|
+
|
5
|
+
> ##### Important information!
|
6
|
+
> To use this gem you must first register your application on GitHub.
|
7
|
+
> For more information on how to register your app and the GitHub
|
8
|
+
> Oauth API have a look here:
|
9
|
+
> https://developer.github.com/guides/basics-of-authentication
|
10
|
+
|
11
|
+
##Usage
|
12
|
+
|
13
|
+
After registering on GitHub you will be provided with a
|
14
|
+
*Client ID* and a *Client Secret*. These keys will be used to
|
15
|
+
identify your application when communicating with the GitHub API.
|
16
|
+
|
17
|
+
To use the ghoa gem you need to require it, and set your API keys,
|
18
|
+
like this:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "ghoa"
|
22
|
+
|
23
|
+
ghoa = Ghoa.new(client_id, client_secret)
|
24
|
+
```
|
25
|
+
|
26
|
+
Redirect the user to `ghoa.authorize_url` in order for them to
|
27
|
+
authorize your application.
|
28
|
+
|
29
|
+
As soon as the application is authorized the user will be
|
30
|
+
redirected to the call back URL you provided when registering
|
31
|
+
the application.
|
32
|
+
|
33
|
+
In addition to the redirection, GitHub will add a code to the
|
34
|
+
call back URL. The URL will look something like this:
|
35
|
+
`http://localhost:9393/github_oauth?code=71458a8b9256a976f156`
|
36
|
+
|
37
|
+
Use this code to fetch an Access Token. You will need the token
|
38
|
+
to retrieve the user's GitHub information:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
access_token = ghoa.fetch_access_token(code)
|
42
|
+
```
|
43
|
+
|
44
|
+
To fetch the user do:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
user = ghoa.fetch_user(access_token)
|
48
|
+
```
|
49
|
+
|
50
|
+
For more examples have a look at the test application that can be
|
51
|
+
found in `test/app.rb`
|
52
|
+
|
53
|
+
##Installation
|
54
|
+
|
55
|
+
```
|
56
|
+
$ gem install ghoa
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
|
data/ghoa.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "ghoa"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.summary = "Ruby gem for simple GitHub authentication"
|
5
|
+
s.description = s.summary
|
6
|
+
s.authors = ["Mayn Kjær", "Cecilia Rivero"]
|
7
|
+
s.email = ["mayn.kjaer@gmail.com", "contact@ceciliarivero.com"]
|
8
|
+
s.homepage = "https://github.com/punchgirls/ghoa"
|
9
|
+
s.license = "MIT"
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
|
13
|
+
s.add_dependency "requests"
|
14
|
+
s.add_development_dependency "cuba"
|
15
|
+
end
|
data/lib/ghoa.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "requests"
|
2
|
+
|
3
|
+
class Ghoa
|
4
|
+
AUTHORIZE_URL = "https://github.com/login/oauth/authorize?client_id=%s"
|
5
|
+
ACCESS_TOKEN_URL = "https://github.com/login/oauth/access_token"
|
6
|
+
USER_URL = "https://api.github.com/user"
|
7
|
+
|
8
|
+
def initialize(client_id, client_secret)
|
9
|
+
@client_id = client_id
|
10
|
+
@client_secret = client_secret
|
11
|
+
end
|
12
|
+
|
13
|
+
def authorize_url
|
14
|
+
return sprintf(AUTHORIZE_URL, @client_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch_access_token(code)
|
18
|
+
response = Requests.request("POST", ACCESS_TOKEN_URL,
|
19
|
+
data: { client_id: @client_id,
|
20
|
+
client_secret: @client_secret,
|
21
|
+
code: code },
|
22
|
+
headers: { "Accept" => "application/json" })
|
23
|
+
|
24
|
+
return response.json["access_token"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch_user(access_token)
|
28
|
+
params = { access_token: access_token }
|
29
|
+
response = Requests.request("GET", USER_URL, params: params)
|
30
|
+
|
31
|
+
return response.json
|
32
|
+
end
|
33
|
+
end
|
data/test/app.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "cuba"
|
2
|
+
require_relative "../lib/ghoa"
|
3
|
+
|
4
|
+
CLIENT_ID = ENV.fetch("CLIENT_ID")
|
5
|
+
CLIENT_SECRET = ENV.fetch("CLIENT_SECRET")
|
6
|
+
|
7
|
+
Cuba.define do
|
8
|
+
ghoa = Ghoa.new(CLIENT_ID, CLIENT_SECRET)
|
9
|
+
|
10
|
+
on "github_oauth" do
|
11
|
+
on param("code") do |code|
|
12
|
+
access_token = ghoa.fetch_access_token(code)
|
13
|
+
|
14
|
+
on access_token != nil do
|
15
|
+
user = ghoa.fetch_user(access_token)
|
16
|
+
|
17
|
+
res.write JSON.dump(user)
|
18
|
+
end
|
19
|
+
|
20
|
+
on default do
|
21
|
+
res.write "An error occured!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
on get, root do
|
26
|
+
res.redirect ghoa.authorize_url
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/config.ru
ADDED
data/test/makefile
ADDED
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghoa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mayn Kjær
|
8
|
+
- Cecilia Rivero
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: requests
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: cuba
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Ruby gem for simple GitHub authentication
|
43
|
+
email:
|
44
|
+
- mayn.kjaer@gmail.com
|
45
|
+
- contact@ceciliarivero.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gems"
|
51
|
+
- ".gitignore"
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- ghoa.gemspec
|
55
|
+
- lib/ghoa.rb
|
56
|
+
- test/app.rb
|
57
|
+
- test/config.ru
|
58
|
+
- test/makefile
|
59
|
+
homepage: https://github.com/punchgirls/ghoa
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.3.0
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Ruby gem for simple GitHub authentication
|
83
|
+
test_files: []
|