jive-oauth2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01765370515637f56ce04d49f479ebeaa728f392
4
+ data.tar.gz: 0295e76cacc6f6daf55fe90a66a82e7aea75aa73
5
+ SHA512:
6
+ metadata.gz: b571505c728738e0dd653c0a2c6aabf11a001c10fb1ca90d1c2a2fb886a13cecdb2ae9ffa82b34fd9bdb5c6d4d596d22e22f11d6f5a69dc8be7f1cc1f49d5d9f
7
+ data.tar.gz: 8874c56f9578ec8ad709cabf040bfd74482a63bbc6b55d9adebab0547b1007595406f34548c9714060bcc34d2ba490319348b7d6559e4518d6b58f37568bb213
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jive-oauth2.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Butch Marshall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Jive::OAuth2
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jive/oauth2`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jive-oauth2'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jive-oauth2
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jive-oauth2.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jive/oauth2"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jive/oauth2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jive-oauth2"
8
+ spec.version = Jive::OAuth2::VERSION
9
+ spec.authors = ["Butch Marshall"]
10
+ spec.email = ["butch.a.marshall@gmail.com"]
11
+
12
+ spec.summary = %q{Basic OAuth2 support for Jive}
13
+ spec.description = %q{Utility functions for dealing with OAuth2 and Jive}
14
+ spec.homepage = "https://github.com/butchmarshall/ruby-jive-oauth2"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "cgi-query_string", "~> 0.1.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,138 @@
1
+ require "jive/oauth2/version"
2
+ require "json"
3
+ require "ostruct"
4
+ require "base64"
5
+ require "uri"
6
+ require "net/http"
7
+ require "cgi"
8
+ require "cgi/query_string"
9
+
10
+ module Jive
11
+ module OAuth2
12
+ module_function
13
+
14
+ # Builds an authorize url
15
+ #
16
+ # TODO - detailed description
17
+ #
18
+ # * *Args* :
19
+ # - +options+ -> options
20
+ # - +callback+ -> callback
21
+ # - +context+ -> context
22
+ # - +extra_auth_params+ -> extra_auth_params
23
+ # * *Returns* :
24
+ # - url
25
+ # * *Raises* :
26
+ # - +ArgumentError+ -> if not right
27
+ #
28
+ def build_authorize_url_response_map(options, callback, context, extra_auth_params = {})
29
+ oauth2_conf = ::OpenStruct.new(options).to_h
30
+
31
+ state_to_encode = {
32
+ :jiveRedirectUrl => callback,
33
+ :client_id => oauth2_conf[:oauth2ConsumerKey]
34
+ }
35
+
36
+ if (context)
37
+ state_to_encode = state_to_encode.merge(context);
38
+ end
39
+
40
+ redirect_uri = oauth2_conf[:clientOAuth2CallbackUrl]
41
+
42
+ query_params = {
43
+ :redirect_uri => redirect_uri,
44
+ :client_id => oauth2_conf[:oauth2ConsumerKey],
45
+ :response_type => "code",
46
+ };
47
+
48
+ if !oauth2_conf[:oauth2Scope].nil?
49
+ query_params[:scope] = oauth2_conf[:oauth2Scope]
50
+ end
51
+
52
+ if extra_auth_params.is_a?(Hash)
53
+ query_params = query_params.merge(extra_auth_params);
54
+ end
55
+
56
+ state = ::Base64.encode64(state_to_encode.to_json.to_json)
57
+
58
+ uri = URI.parse(oauth2_conf[:originServerAuthorizationUrl])
59
+
60
+ if uri.query
61
+ ::CGI.parse(uri.query)
62
+ end
63
+
64
+ return {
65
+ :url => "#{uri.scheme}://#{uri.host}#{uri.path}?state=#{state}&#{::CGI::QueryString.param(query_params)}"
66
+ }
67
+ end
68
+
69
+ # Builds a callback object
70
+ #
71
+ # TODO - detailed description
72
+ #
73
+ # * *Args* :
74
+ # - +options+ -> options
75
+ # - +code+ -> code
76
+ # - +extra_params+ -> extra_params
77
+ # * *Returns* :
78
+ # - callback object
79
+ # * *Raises* :
80
+ # - +ArgumentError+ -> if not right
81
+ #
82
+ def build_oauth2_callback_object(options, code, extra_params = {})
83
+ oauth2_conf = ::OpenStruct.new(options).to_h
84
+
85
+ redirect_uri = oauth2_conf[:clientOAuth2CallbackUrl]
86
+
87
+ post_object = {
88
+ :grant_type => 'authorization_code',
89
+ :redirect_uri => redirect_uri,
90
+ :client_id => oauth2_conf[:oauth2ConsumerKey],
91
+ :client_secret => oauth2_conf[:oauth2ConsumerSecret],
92
+ :code => code,
93
+ };
94
+
95
+ if !oauth2_conf[:oauth2CallbackExtraParams].nil?
96
+ post_object = post_object.merge oauth2_conf[:oauth2CallbackExtraParams]
97
+ end
98
+
99
+ if extra_params.is_a?(Hash)
100
+ post_object = post_object.merge(extra_params)
101
+ end
102
+
103
+ return post_object
104
+ end
105
+
106
+ # Retrieves oauth token from server
107
+ #
108
+ # TODO - detailed description
109
+ #
110
+ # * *Args* :
111
+ # - +options+ -> options
112
+ # - +post_object+ -> post_object
113
+ # * *Returns* :
114
+ # - oauth token response
115
+ # * *Raises* :
116
+ # - +ArgumentError+ -> if not right
117
+ #
118
+ def get_oauth2_token(options, post_object)
119
+ oauth2_conf = ::OpenStruct.new(options).to_h
120
+
121
+ uri = URI(oauth2_conf[:originServerTokenRequestUrl])
122
+ req = Net::HTTP::Post.new(uri.path)
123
+ req.set_form_data(post_object)
124
+ req['Content-Type'] = 'application/x-www-form-urlencoded'
125
+
126
+ res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) do |http|
127
+ http.request(req)
128
+ end
129
+
130
+ case res
131
+ when Net::HTTPSuccess, Net::HTTPRedirection
132
+ res.body
133
+ else
134
+ res.value
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,5 @@
1
+ module Jive
2
+ module OAuth2
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jive-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Butch Marshall
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cgi-query_string
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Utility functions for dealing with OAuth2 and Jive
70
+ email:
71
+ - butch.a.marshall@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - jive-oauth2.gemspec
86
+ - lib/jive/oauth2.rb
87
+ - lib/jive/oauth2/version.rb
88
+ homepage: https://github.com/butchmarshall/ruby-jive-oauth2
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.8
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Basic OAuth2 support for Jive
112
+ test_files: []