github-oauth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/github-oauth.gemspec +23 -0
- data/lib/github-oauth.rb +5 -0
- data/lib/github-oauth/authentication.rb +15 -0
- data/lib/github-oauth/version.rb +3 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
This is a simple gem that helps you authenticate via the Github API V3 using OAuth2
|
2
|
+
-----------------------------------------------------------------------------------
|
3
|
+
|
4
|
+
This is a simple example on how to use the gem (here using sinatra routes). The gem will use the "callback_url" from your Github application OAuth settings (in this case I set it to http://mysite.com/oauth).
|
5
|
+
|
6
|
+
# when user lands on home page
|
7
|
+
get '/' do
|
8
|
+
# check if we already have a token
|
9
|
+
unless session[:access_token]
|
10
|
+
# if not, redirect to the github authorication url
|
11
|
+
redirect GithubOAuth.authorize_url('github_client_id', 'github_client_secret')
|
12
|
+
end
|
13
|
+
"You have authenticated"
|
14
|
+
end
|
15
|
+
|
16
|
+
# when the user comes back from the github authorization url
|
17
|
+
get '/oauth' do
|
18
|
+
# save the token in a session. append this token to all calls to the github api
|
19
|
+
session[:access_token] = GithubOAuth.token('github_client_id', 'github_client_secret', params[:code])
|
20
|
+
redirect '/'
|
21
|
+
end
|
22
|
+
|
23
|
+
I'm planning on releasing my GithubAPI gem that takes this token and makes read/write operations to the Github API super simple.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "github-oauth"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["Rune Madsen"]
|
8
|
+
s.email = ["rune@runemadsen.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{A simple gem to handle the Github OAuth authentication}
|
11
|
+
s.description = %q{A simple gem to handle the Github OAuth authentication}
|
12
|
+
|
13
|
+
s.rubyforge_project = "github-oauth"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
# s.add_development_dependency "rspec"
|
22
|
+
s.add_dependency "oauth2"
|
23
|
+
end
|
data/lib/github-oauth.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module GithubOAuth
|
2
|
+
|
3
|
+
def self.github_client(client_id, client_secret)
|
4
|
+
OAuth2::Client.new(client_id, client_secret, :authorize_url => 'https://github.com/login/oauth/authorize', :token_url => 'https://github.com/login/oauth/access_token')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.authorize_url(client_id, client_secret, scope = "repo,gist")
|
8
|
+
self.github_client(client_id, client_secret).auth_code.authorize_url(:scope => scope)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.token(client_id, client_secret, code)
|
12
|
+
self.github_client(client_id, client_secret).auth_code.get_token(code).token
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Rune Madsen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-30 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: oauth2
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A simple gem to handle the Github OAuth authentication
|
35
|
+
email:
|
36
|
+
- rune@runemadsen.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- github-oauth.gemspec
|
49
|
+
- lib/github-oauth.rb
|
50
|
+
- lib/github-oauth/authentication.rb
|
51
|
+
- lib/github-oauth/version.rb
|
52
|
+
homepage: ""
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: github-oauth
|
81
|
+
rubygems_version: 1.8.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: A simple gem to handle the Github OAuth authentication
|
85
|
+
test_files: []
|
86
|
+
|