Skip to content

Commit

Permalink
Initial commit, with working strategy based on omniauth-oauth gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
smudge committed Jan 2, 2014
0 parents commit a647c21
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.gem
*.rbc
.bundle
.config
.yardoc
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
/pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in omniauth-splitwise.gemspec
gemspec
26 changes: 26 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PATH
remote: .
specs:
omniauth-splitwise (0.0.1)
multi_json
omniauth-oauth (~> 1.0.0)

GEM
remote: http://rubygems.org/
specs:
hashie (2.0.5)
multi_json (1.8.2)
oauth (0.4.7)
omniauth (1.1.4)
hashie (>= 1.2, < 3)
rack
omniauth-oauth (1.0.1)
oauth
omniauth (~> 1.0)
rack (1.5.2)

PLATFORMS
ruby

DEPENDENCIES
omniauth-splitwise!
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# OmniAuth Splitwise

An OmniAuth strategy for authenticating to [Splitwise](http://www.splitwise.com). To use it, you'll need to [sign up for a Consumer Key and Secret](https://secure.splitwise.com/oauth_clients).

## Installation

Add this line to your application's Gemfile:

gem 'omniauth-splitwise'

And then execute:

$ bundle

Or install it yourself:

$ gem install omniauth-splitwise

## Usage

For Rack apps, in your config.ru:

```ruby
use OmniAuth::Builder do
provider :splitwise, ENV['SPLITWISE_KEY'], ENV['SPLITWISE_SECRET']
end
```

For Rails apps, in config/initializers/omniauth.rb:

```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
provider :splitwise, ENV['SPLITWISE_KEY'], ENV['SPLITWISE_SECRET']
end
```

See also: [Integrating OmniAuth Into Your Application](https://github.com/intridea/omniauth#integrating-omniauth-into-your-application).

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

# License

Copyright (C) 2014 by Nathan Griffith

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions lib/omniauth-splitwise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "omniauth/splitwise/version"
require 'omniauth/strategies/splitwise'
5 changes: 5 additions & 0 deletions lib/omniauth/splitwise/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OmniAuth
module Splitwise
VERSION = "0.0.1"
end
end
37 changes: 37 additions & 0 deletions lib/omniauth/strategies/splitwise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'omniauth/strategies/oauth'

module OmniAuth
module Strategies
class Splitwise < OmniAuth::Strategies::OAuth
option :name, "splitwise"

option :client_options, {
:site => 'https://secure.splitwise.com',
:request_token_path => '/api/v3.0/get_request_token',
:access_token_path => '/api/v3.0/get_access_token',
:authorize_path => '/authorize',
:http_method => :post,
:scheme => :header
}

uid do
user_data['id']
end

info do
user_data
end

private

def user_data
@info ||= MultiJson.decode(access_token.get('/api/v3.0/get_current_user').body)['user']
end

def callback_phase
session['oauth'][name.to_s]['callback_confirmed'] = true
super
end
end
end
end
20 changes: 20 additions & 0 deletions omniauth-splitwise.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'omniauth/splitwise/version'

Gem::Specification.new do |s|
s.name = 'omniauth-splitwise'
s.version = OmniAuth::Splitwise::VERSION
s.authors = ['Nathan Griffith']
s.email = ['nathan@ngriffith.com']
s.summary = 'Splitwise strategy for OmniAuth'
s.homepage = 'https://github.com/Smudge/omniauth-splitwise'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.add_runtime_dependency 'omniauth-oauth', '~> 1.0.0'
s.add_runtime_dependency 'multi_json'
end

0 comments on commit a647c21

Please sign in to comment.