Permalink
Browse files

initial

  • Loading branch information...
nashby committed Jun 27, 2012
0 parents commit 357c572af721e5a8494d1219a9b5ee6688bf0285
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,6 @@
+source 'https://rubygems.org'
+
+gemspec
+
+gem 'rake'
+gem 'minitest', '~> 3.0'
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Vasiliy Ermolovich
+
+MIT License
+
+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.
@@ -0,0 +1,41 @@
+# OmniAuth StackExchange
+
+This gem contains the StackExchange strategy for OmniAuth.
+
+StackExchange uses the OAuth2 flow, you can read about it here: https://api.stackexchange.com/docs/authentication
+
+## How To Use It
+
+So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
+
+ gem 'omniauth-stackexchange'
+
+You can pull them in directly from github e.g.:
+
+ gem 'omniauth-stackexchange', :git => 'https://github.com/nashby/omniauth-stackexchange.git'
+
+Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
+
+ Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :stackexchange, "client_id", "client_secret", public_key: "key"
+ end
+
+You will obviously have to put in your client_id, client_secret and public_key, which you get when you register your app with StackExchange (they call them Client Id, Client Secret and Key).
+
+Now just follow the README at: https://github.com/intridea/omniauth
+
+## Supported Rubies
+
+OmniAuth StackExchange is tested under 1.9.3.
+
+## 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) 2011 by Arun Agrawal
@@ -0,0 +1,11 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << 'test'
+ t.pattern = 'test/*_test.rb'
+ t.verbose = true
+end
+
+task :default => :test
@@ -0,0 +1,2 @@
+require 'omniauth-stackexchange/version'
+require 'omniauth/strategies/stackexchange'
@@ -0,0 +1,5 @@
+module Omniauth
+ module StackExchange
+ VERSION = "0.0.1"
+ end
+end
@@ -0,0 +1,52 @@
+require 'omniauth-oauth2'
+
+module OmniAuth
+ module Strategies
+ class StackExchange < OmniAuth::Strategies::OAuth2
+ option :client_options, {
+ :site => 'https://api.stackexchange.com/2.0',
+ :authorize_url => 'https://stackexchange.com/oauth',
+ :token_url => 'https://stackexchange.com/oauth/access_token'
+ }
+
+ option :token_params, {
+ :parse => :query
+ }
+
+ def request_phase
+ super
+ end
+
+ uid { raw_info['user_id'] }
+
+ info do
+ {
+ 'nickname' => raw_info['display_name'],
+ 'image' => raw_info['profile_image'],
+ 'urls' => {
+ 'StackOverflow' => raw_info['link']
+ },
+
+ }
+ end
+
+ extra do
+ { :raw_info => raw_info }
+ end
+
+ def raw_info
+ @raw_info ||= access_token.get('me', :params => params).parsed['items'].first
+ end
+
+ def params
+ {
+ :site => 'stackoverflow',
+ :access_token => access_token.token,
+ :key => options.public_key
+ }
+ end
+ end
+ end
+end
+
+OmniAuth.config.add_camelization 'stackexchange', 'StackExchange'
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/omniauth-stackexchange/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Vasiliy Ermolovich"]
+ gem.email = ["younash@gmail.com"]
+ gem.description = %q{StackExchange OAuth strategy for OmniAuth}
+ gem.summary = %q{StackExchange OAuth strategy for OmniAuth}
+ gem.homepage = "https://github.com/nashby/omniauth-stackexchange"
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "omniauth-stackexchange"
+ gem.require_paths = ["lib"]
+ gem.version = Omniauth::StackExchange::VERSION
+
+ gem.add_dependency 'omniauth', '~> 1.0'
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
+end
@@ -0,0 +1,19 @@
+require 'test_helper'
+
+describe OmniAuth::Strategies::StackExchange do
+ let(:stackexchange) do
+ OmniAuth::Strategies::StackExchange.new({})
+ end
+
+ it 'has correct site' do
+ stackexchange.options.client_options.site.must_equal("https://api.stackexchange.com/2.0")
+ end
+
+ it 'has correct authorize url' do
+ stackexchange.options.client_options.authorize_url.must_equal('https://stackexchange.com/oauth')
+ end
+
+ it 'has correct token url' do
+ stackexchange.options.client_options.token_url.must_equal('https://stackexchange.com/oauth/access_token')
+ end
+end
@@ -0,0 +1,5 @@
+require 'minitest/autorun'
+require 'minitest/spec'
+
+require 'omniauth'
+require 'omniauth-stackexchange'

0 comments on commit 357c572

Please sign in to comment.