mirror of
https://github.com/elyby/omniauth-ely.git
synced 2024-11-26 08:42:09 +05:30
Initial commit
This commit is contained in:
commit
d8abf6d0ba
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
.idea
|
||||
*.gem
|
||||
*.rbc
|
||||
.bundle
|
||||
.config
|
||||
.yardoc
|
||||
Gemfile.lock
|
||||
InstalledFiles
|
||||
_yardoc
|
||||
coverage
|
||||
doc/
|
||||
lib/bundler/man
|
||||
/pkg
|
||||
rdoc
|
||||
spec/reports
|
||||
test/tmp
|
||||
test/version_tmp
|
||||
tmp
|
12
Gemfile
Normal file
12
Gemfile
Normal file
@ -0,0 +1,12 @@
|
||||
source 'http://rubygems.org'
|
||||
|
||||
# Specify your gem's dependencies in omniauth-ely.gemspec
|
||||
gemspec
|
||||
|
||||
group :development, :test do
|
||||
gem 'guard'
|
||||
gem 'guard-rspec'
|
||||
gem 'guard-bundler'
|
||||
gem 'rb-fsevent'
|
||||
gem 'growl'
|
||||
end
|
10
Guardfile
Normal file
10
Guardfile
Normal file
@ -0,0 +1,10 @@
|
||||
guard 'rspec', :version => 2 do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
end
|
||||
|
||||
guard 'bundler' do
|
||||
watch('Gemfile')
|
||||
watch('omniauth-ely.gemspec')
|
||||
end
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Ely.by <team@ely.by>
|
||||
|
||||
> 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.
|
26
README.md
Normal file
26
README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# OmniAuth Ely.by
|
||||
|
||||
This is the official OmniAuth strategy for authenticating to Ely.by. To
|
||||
use it, you'll need to sign up for an OAuth2 Application ID and Secret
|
||||
on the [Ely.by Account Applications Page](#).
|
||||
|
||||
## Usage
|
||||
|
||||
Add the strategy to your `Gemfile` alongside OmniAuth:
|
||||
|
||||
```ruby
|
||||
gem 'omniauth'
|
||||
gem 'omniauth-ely'
|
||||
```
|
||||
|
||||
Integrate this strategy to your OmniAuth middleware.
|
||||
|
||||
```ruby
|
||||
use OmniAuth::Builder do
|
||||
provider :ely, 'application_id', 'secret'
|
||||
end
|
||||
```
|
||||
|
||||
You need to add your key and secret.
|
||||
|
||||
For more information check the [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
|
8
Rakefile
Normal file
8
Rakefile
Normal file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env rake
|
||||
require "bundler/gem_tasks"
|
||||
require 'rspec/core/rake_task'
|
||||
|
||||
RSpec::Core::RakeTask.new
|
||||
|
||||
desc 'Run specs'
|
||||
task :default => :spec
|
2
lib/omniauth-ely.rb
Normal file
2
lib/omniauth-ely.rb
Normal file
@ -0,0 +1,2 @@
|
||||
require 'omniauth-ely/version'
|
||||
require 'omniauth/strategies/ely'
|
5
lib/omniauth-ely/version.rb
Normal file
5
lib/omniauth-ely/version.rb
Normal file
@ -0,0 +1,5 @@
|
||||
module OmniAuth
|
||||
module Ely
|
||||
VERSION = '0.1.0'
|
||||
end
|
||||
end
|
49
lib/omniauth/strategies/ely.rb
Normal file
49
lib/omniauth/strategies/ely.rb
Normal file
@ -0,0 +1,49 @@
|
||||
require 'omniauth-oauth2'
|
||||
|
||||
module OmniAuth
|
||||
module Strategies
|
||||
class Ely < OmniAuth::Strategies::OAuth2
|
||||
option :client_options, {
|
||||
:site => 'https://account.ely.by',
|
||||
:authorize_url => 'https://account.ely.by/oauth2/v1/',
|
||||
:token_url => 'https://account.ely.by/api/oauth2/v1/token',
|
||||
}
|
||||
|
||||
uid { raw_info['id'].to_s }
|
||||
|
||||
info do
|
||||
{
|
||||
:name => raw_info['username'],
|
||||
:email => raw_info['email'],
|
||||
:urls => {
|
||||
:Ely => profile_url,
|
||||
:Skin => skin_url,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
extra do
|
||||
{
|
||||
:raw_info => raw_info,
|
||||
:uuid => raw_info['uuid'],
|
||||
:registered_at => raw_info['registeredAt'],
|
||||
:preferred_language => raw_info['preferredLanguage']
|
||||
}
|
||||
end
|
||||
|
||||
def raw_info
|
||||
@raw_info ||= access_token.get('https://account.ely.by/api/account/v1/info').parsed
|
||||
end
|
||||
|
||||
def skin_url
|
||||
'http://skinsystem.ely.by/skins/' + raw_info['username'] + '.png'
|
||||
end
|
||||
|
||||
def profile_url
|
||||
'http://ely.by/u' + raw_info['id'].to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
OmniAuth.config.add_camelization 'ely', 'Ely'
|
27
omniauth-ely.gemspec
Normal file
27
omniauth-ely.gemspec
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
require File.expand_path('../lib/omniauth-ely/version', __FILE__)
|
||||
|
||||
Gem::Specification.new do |gem|
|
||||
gem.name = 'omniauth-ely'
|
||||
gem.version = OmniAuth::Ely::VERSION
|
||||
gem.homepage = 'https://github.com/elyby/omniauth-ely'
|
||||
gem.license = 'MIT'
|
||||
|
||||
gem.authors = ['Ely.by team', 'ErickSkrauch']
|
||||
gem.email = ['team@ely.by', 'erickskrauch@ely.by']
|
||||
gem.description = %q{Official OmniAuth strategy for Ely.by.}
|
||||
gem.summary = %q{Official OmniAuth strategy for Ely.by.}
|
||||
|
||||
gem.add_dependency 'omniauth', '~> 1.0'
|
||||
gem.add_dependency 'omniauth-oauth2', '>= 1.1.1', '< 2.0'
|
||||
gem.add_development_dependency 'rspec', '~> 2.7'
|
||||
gem.add_development_dependency 'rack-test'
|
||||
gem.add_development_dependency 'simplecov'
|
||||
gem.add_development_dependency 'webmock'
|
||||
|
||||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||
gem.files = `git ls-files`.split("\n")
|
||||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
|
||||
gem.require_paths = ['lib']
|
||||
end
|
50
spec/omniauth/strategies/ely_spec.rb
Normal file
50
spec/omniauth/strategies/ely_spec.rb
Normal file
@ -0,0 +1,50 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe OmniAuth::Strategies::Ely do
|
||||
let(:access_token) { stub('AccessToken', :options => {}) }
|
||||
let(:parsed_response) { stub('ParsedResponse') }
|
||||
let(:response) { stub('Response', :parsed => parsed_response) }
|
||||
|
||||
subject do
|
||||
OmniAuth::Strategies::Ely.new({})
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
subject.stub!(:access_token).and_return(access_token)
|
||||
end
|
||||
|
||||
context 'client options' do
|
||||
it 'should have correct site' do
|
||||
subject.options.client_options.site.should eq('https://account.ely.by')
|
||||
end
|
||||
|
||||
it 'should have correct authorize url' do
|
||||
subject.options.client_options.authorize_url.should eq('https://account.ely.by/oauth2/v1/')
|
||||
end
|
||||
|
||||
it 'should have correct token url' do
|
||||
subject.options.client_options.token_url.should eq('https://account.ely.by/api/oauth2/v1/token')
|
||||
end
|
||||
end
|
||||
|
||||
context '#raw_info' do
|
||||
it 'should use relative paths' do
|
||||
access_token.should_receive(:get).and_return(response)
|
||||
subject.raw_info.should eq(parsed_response)
|
||||
end
|
||||
|
||||
it 'should build valid profile link' do
|
||||
raw_info = Hash.new
|
||||
raw_info['id'] = 1
|
||||
subject.stub!(:raw_info).and_return(raw_info)
|
||||
subject.profile_url.should eq('http://ely.by/u1')
|
||||
end
|
||||
|
||||
it 'should build valid skin link' do
|
||||
raw_info = Hash.new
|
||||
raw_info['username'] = 'Steve'
|
||||
subject.stub!(:raw_info).and_return(raw_info)
|
||||
subject.skin_url.should eq('http://skinsystem.ely.by/skins/Steve.png')
|
||||
end
|
||||
end
|
||||
end
|
15
spec/spec_helper.rb
Normal file
15
spec/spec_helper.rb
Normal file
@ -0,0 +1,15 @@
|
||||
$:.unshift File.expand_path('..', __FILE__)
|
||||
$:.unshift File.expand_path('../../lib', __FILE__)
|
||||
require 'simplecov'
|
||||
SimpleCov.start
|
||||
require 'rspec'
|
||||
require 'rack/test'
|
||||
require 'webmock/rspec'
|
||||
require 'omniauth'
|
||||
require 'omniauth-ely'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include WebMock::API
|
||||
config.include Rack::Test::Methods
|
||||
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
||||
end
|
Loading…
Reference in New Issue
Block a user