Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit d2d9e9cde6754df5bbfd27bfac3b7a7b31fb7039 @kirs kirs committed Nov 26, 2011
Showing with 141 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +1 −0 .rspec
  3. +5 −0 .travis.yml
  4. +3 −0 Gemfile
  5. +18 −0 README.md
  6. +1 −0 Rakefile
  7. +8 −0 lib/omniauth-yandex.rb
  8. +5 −0 lib/omniauth-yandex/version.rb
  9. +72 −0 lib/omniauth/strategies/yandex.rb
  10. +23 −0 omniauth-yandex.gemspec
5 .gitignore
@@ -0,0 +1,5 @@
+*.swp
+*.swo
+Gemfile.lock
+coverage
+*.gem
1 .rspec
@@ -0,0 +1 @@
+--colour
5 .travis.yml
@@ -0,0 +1,5 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - ree
3 Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
18 README.md
@@ -0,0 +1,18 @@
+# OmniAuth Yandex.ru
+
+This gem contains the unofficial Yandex.ru OAuth2 strategy for [OmniAuth](http://github.com/intridea/omniauth).
+
+## Basic Usage
+
+ use OmniAuth::Builder do
+ provider :yandex, ENV['YANDEX_KEY'], ENV['YANDEX_PRIVATE_KEY']
+ end
+
+
+## Links
+
+* http://api.yandex.ru/oauth/
+
+## License
+
+Copyright (c) 2011 by Kirill Shatrov
1 Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
8 lib/omniauth-yandex.rb
@@ -0,0 +1,8 @@
+require "omniauth"
+require "omniauth-yandex/version"
+
+module OmniAuth
+ module Strategies
+ autoload :Yandex, "omniauth/strategies/yandex"
+ end
+end
5 lib/omniauth-yandex/version.rb
@@ -0,0 +1,5 @@
+module Omniauth
+ module Yandex
+ VERSION = "0.0.1"
+ end
+end
72 lib/omniauth/strategies/yandex.rb
@@ -0,0 +1,72 @@
+require 'omniauth/strategies/oauth2'
+require 'xmlsimple'
+
+module OmniAuth
+ module Strategies
+
+ # Authenticate to Yandex.ru utilizing OAuth 2.0
+ # http://api.yandex.ru/oauth/
+
+ class Yandex < OmniAuth::Strategies::OAuth2
+ option :name, "yandex"
+
+ option :client_options, {
+ :site => 'https://oauth.yandex.ru/',
+ :token_url => '/token',
+ :authorize_url => '/authorize'
+ }
+
+ uid do
+ raw_info[:uid]
+ end
+
+ info do
+ {
+ :nickname => raw_info[:name],
+ :email => raw_info[:email],
+ :name => raw_info[:name],
+ :image => raw_info[:photo],
+ :location => raw_info[:country],
+ :urls => {
+ 'Yandex' => raw_info[:yaru_profile]
+ }
+ }
+ end
+
+ extra do
+ {:raw_info => raw_info}
+ end
+
+ def callback_url
+ if options.authorize_options.respond_to? :callback_url
+ options.authorize_options.callback_url
+ else
+ super
+ end
+ end
+
+ private
+
+ def raw_info
+ @raw_info ||= begin
+ # Get user info from Ya.ru API
+ # http://api.yandex.ru/yaru/doc/ref/concepts/discovery.xml
+ xml_data = access_token.get("https://api-yaru.yandex.ru/me/").body
+ data = XmlSimple.xml_in(xml_data)
+ {
+ :uid => data["id"][0],
+ :yaru_profile => data["link"][0]["href"],
+ :photo => data["link"][2]["href"],
+ :name => data["name"][0],
+ :email => data["email"][0],
+ :country => data["country"][0],
+ :city => data["city"][0],
+ :sex => data["sex"][0],
+ :skype => data["skype"][0]
+ }
+ end
+ end
+
+ end
+ end
+end
23 omniauth-yandex.gemspec
@@ -0,0 +1,23 @@
+$:.push File.expand_path("../lib", __FILE__)
+require "omniauth-yandex/version"
+
+Gem::Specification.new do |s|
+ s.name = "omniauth-yandex"
+ s.version = Omniauth::Yandex::VERSION
+ s.authors = ["Kir Shatrov"]
+ s.email = ["shatrov@me.com"]
+ s.homepage = "https://github.com/kirs/omniauth-yandex"
+ s.summary = %q{OmniAuth strategy for Yandex.ru}
+ s.description = %q{OmniAuth strategy for Yandex.ru}
+
+ s.rubyforge_project = "omniauth-yandex"
+
+ 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_dependency 'omniauth', '~> 1.0'
+ s.add_dependency 'omniauth-oauth2', '~> 1.0'
+ s.add_dependency 'xml-simple'
+end

0 comments on commit d2d9e9c

Please sign in to comment.