Skip to content

Commit

Permalink
add strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
suer committed Jun 21, 2013
1 parent b7dd641 commit 0b13f66
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
# Omniauth::Redmine

TODO: Write a gem description
Strategy to authenticate with Redmine via OAuth in Redmine.
(https://github.com/suer/redmine_oauth_provider)

## Installation

Build gem package:

$ rake build

Unpack gem package in your application's root directory:

$ gem unpack some/directory/pkg/omniauth-redmine-X.Y.Z.gem

Add this line to your application's Gemfile:

gem 'omniauth-redmine'
gem 'omniauth-redmine', :path => 'omniauth-redmine-X.Y.Z'

And then execute:

$ bundle
$ bundle install --path .bundle

Or install it yourself as:

$ gem install omniauth-redmine
$ gem install pkg/omniauth-redmine-X.Y.Z.gem

## Usage

TODO: Write usage instructions here
Here's an example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
provider :redmine, "consumer key", "consumer secret", :redmine_base_url => "http://redmine.base.url/"
end

If you use devise, add this lines in config/initializers/devise.rb

config.omniauth :redmine, "consumer key", "consumer secret", :redmine_base_url => "http://redmine.base.url/"

## License
The MIT License (MIT)
Copyright (c) 2013 suer

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:

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

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
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.
1 change: 1 addition & 0 deletions lib/omniauth-redmine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'omniauth/redmine'
8 changes: 1 addition & 7 deletions lib/omniauth/redmine.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
require "omniauth/redmine/version"

module Omniauth
module Redmine
# Your code goes here...
end
end
require 'omniauth/strategies/redmine'
37 changes: 37 additions & 0 deletions lib/omniauth/strategies/redmine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'omniauth/strategies/oauth'

module OmniAuth
module Strategies
class Redmine < OmniAuth::Strategies::OAuth

def consumer
options.client_options = {
:authorize_url => "#{redmine_base_url}oauth/authorize",
:request_token_url => "#{redmine_base_url}oauth/request_token",
:access_token_url => "#{redmine_base_url}oauth/access_token"
}
super
end

uid { raw_info['user']['id'] }

info do
{
'nickname' => raw_info['user']['mail'],
'email' => raw_info['user']['mail'],
'name' => "#{raw_info['user']['lastname']} #{raw_info['user']['firstname']}"
}
end

def raw_info
@raw_info ||= MultiJson.decode(access_token.get("#{redmine_base_url}oauth/user_info.json").body)
end

private
def redmine_base_url
options.redmine_base_url << '/' unless options.redmine_base_url.end_with?('/')
options.redmine_base_url
end
end
end
end
9 changes: 7 additions & 2 deletions omniauth-redmine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'omniauth/redmine/version'

Gem::Specification.new do |spec|
spec.add_dependency 'omniauth', '~> 1.1'

spec.name = "omniauth-redmine"
spec.version = Omniauth::Redmine::VERSION
spec.authors = ["suer"]
spec.email = ["[email protected]"]
spec.description = %q{TODO: Write a gem description}
spec.summary = %q{TODO: Write a gem summary}
spec.description = %q{An OmniAuth strategy for Redmine}
spec.summary = %q{An OmniAuth strategy for Redmine}
spec.homepage = ""
spec.license = "MIT"

Expand All @@ -18,6 +20,9 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency 'omniauth-oauth'
spec.add_runtime_dependency 'multi_json'

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
end

0 comments on commit 0b13f66

Please sign in to comment.