Permalink
Browse files

cloned from bitly code

  • Loading branch information...
1 parent 570e082 commit 4109078b11c3301340d0f8e18eccd2c1013e4504 @judearasu committed Jul 8, 2012
View
@@ -0,0 +1,12 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
+
+desc 'Run specs'
+task :default => :spec
View
@@ -0,0 +1,6 @@
+source :rubygems
+
+gem 'sinatra'
+gem 'multi_json'
+gem 'omniauth-miso', :path => '../'
+gem 'rack'
View
@@ -0,0 +1,39 @@
+require 'bundler/setup'
+require 'sinatra/base'
+require 'omniauth-miso'
+
+ENV['CLIENT_ID']='L342xgomRJ4oTCL7D9cQ'
+ENV['CLIENT_SECRET']='xMTTX0vZ25C6FGOmLOn53je9OQaBC8P21iplqqOH'
+
+
+
+use Rack::Session::Cookie
+
+use OmniAuth::Builder do
+ provider :miso, ENV['CLIENT_ID'], ENV['CLIENT_SECRET']
+end
+
+class App < Sinatra::Base
+ get '/' do
+ <<-HTML
+ <ul>
+ <li><a href='/auth/miso'>Sign in with Miso</a></li>
+ </ul>
+ HTML
+ end
+
+ get '/auth/:provider/callback' do
+ puts "THE RESULT HASH: #{request.env['omniauth.auth']}"
+ end
+
+ get '/auth/failure' do
+ content_type 'text/plain'
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
+ end
+
+
+end
+
+
+run App.new
+
View
@@ -0,0 +1,2 @@
+require "omniauth-miso/version"
+require 'omniauth/strategies/miso'
@@ -0,0 +1,5 @@
+module OmniAuth
+ module Miso
+ VERSION = "0.0.1"
+ end
+end
@@ -0,0 +1,27 @@
+require 'omniauth-oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ class Miso < OmniAuth::Strategies::OAuth
+ option :name, "miso"
+ option :client_options,{:site=>'https://gomiso.com/',
+ :authorize_url => '/oauth/authorize',
+ }
+
+
+ uid { access_token.params[:user_id] }
+ extra do
+ { :raw_info => raw_info }
+ end
+
+ def raw_info
+ @raw_info ||= MultiJson.decode(@access_token.get('/api/oauth/v1/users/show.json').body)['user']
+ rescue ::Errno::ETIMEDOUT
+ raise ::Timeout::Error
+ end
+
+ end
+ end
+end
+OmniAuth.config.add_camelization 'gomiso', 'Miso'
View
@@ -0,0 +1,23 @@
+require File.expand_path('../lib/omniauth-miso/version', __FILE__)
+
+Gem::Specification.new do |s|
+ s.authors = ["Jude Arasu"]
+ s.email = ["judearasu@genlinux.org"]
+ s.description = %q{OmniAuth strategy for Miso.}
+ s.summary = %q{OmniAuth strategy for Miso.}
+ s.homepage = "https://github.com/judearasu/omniauth-miso"
+
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.name = "omniauth-miso"
+ s.require_paths = ["lib"]
+ s.version = OmniAuth::Miso::VERSION
+
+ s.add_dependency 'omniauth', '~> 1.0'
+ s.add_dependency 'omniauth-oauth'
+ s.add_development_dependency 'rspec', '~> 2.7'
+ s.add_development_dependency 'rack-test'
+ s.add_development_dependency 'simplecov'
+ s.add_development_dependency 'webmock'
+end
@@ -1,32 +1,32 @@
require 'spec_helper'
-require 'omniauth-bitly'
+require 'omniauth-miso'
require 'base64'
-describe OmniAuth::Strategies::Bitly do
+describe OmniAuth::Strategies::Miso do
before :each do
@request = double('Request')
@request.stub(:params) { {} }
@request.stub(:cookies) { {} }
@client_id = '123'
@client_secret = '53cr3tz'
- @options = {:client_options => {:site => 'https://bitly.com',:authorize_url=>'/oauth/authorize'}}
+ @options = {:client_options => {:site => 'https://gomiso.com/',:authorize_url=>'/oauth/authorize'}}
end
subject do
args = [@client_id, @client_secret, @options].compact
- OmniAuth::Strategies::Bitly.new(nil, *args).tap do |strategy|
+ OmniAuth::Strategies::Miso.new(nil, *args).tap do |strategy|
strategy.stub(:request) { @request }
end
end
context "client options" do
- it 'has correct bitly name' do
- subject.options.name.should eq('bitly')
+ it 'has correct miso name' do
+ subject.options.name.should eq('miso')
end
it 'has correct site name' do
- subject.options.client_options.site.should eq('https://bitly.com')
+ subject.options.client_options.site.should eq('https://gomiso.com/')
end
it 'has correct authorize url' do
View
@@ -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-miso'
+
+RSpec.configure do |config|
+ config.include WebMock::API
+ config.include Rack::Test::Methods
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
+end

0 comments on commit 4109078

Please sign in to comment.