From 303df962633286a2f71ac99697b4426abac204fe Mon Sep 17 00:00:00 2001 From: bhbryant Date: Tue, 18 May 2010 08:08:51 -0700 Subject: [PATCH] initial working code commit, connects to facebook --- .document | 0 .gitignore | 0 LICENSE | 0 README.rdoc | 0 Rakefile | 11 +++- lib/devise_oauth2_authenticatable.rb | 59 ++++++++++++++++++++++ spec/devise_oauth2_authenticatable_spec.rb | 0 spec/spec.opts | 0 spec/spec_helper.rb | 0 9 files changed, 68 insertions(+), 2 deletions(-) mode change 100644 => 100755 .document mode change 100644 => 100755 .gitignore mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.rdoc mode change 100644 => 100755 Rakefile mode change 100644 => 100755 lib/devise_oauth2_authenticatable.rb mode change 100644 => 100755 spec/devise_oauth2_authenticatable_spec.rb mode change 100644 => 100755 spec/spec.opts mode change 100644 => 100755 spec/spec_helper.rb diff --git a/.document b/.document old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.rdoc b/README.rdoc old mode 100644 new mode 100755 diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 9c0c7e2..0a71a6e --- a/Rakefile +++ b/Rakefile @@ -1,16 +1,23 @@ require 'rubygems' require 'rake' +require File.join(File.dirname(__FILE__), 'lib', 'devise_oauth2_authenticatable', 'version') begin require 'jeweler' Jeweler::Tasks.new do |gem| gem.name = "devise_oauth2_authenticatable" - gem.summary = %Q{TODO: one-line summary of your gem} - gem.description = %Q{TODO: longer description of your gem} + gem.version = ::Devise::Oauth2Authenticatable::VERSION + gem.summary = %{Devise << OAuth2} + gem.description = %{Implements OAuth2 for devises, specifically integrating with facebook Graph} gem.email = "benjamin@bryantmarkowsky.com" gem.homepage = "http://github.com/bhbryant/devise_oauth2_authenticatable" gem.authors = ["bhbryant"] gem.add_development_dependency "rspec", ">= 1.2.9" + + gem.add_dependency'devise', '>= 1.0.0' + gem.add_dependency "oauth2" + gem.add_dependency "json" + # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings end Jeweler::GemcutterTasks.new diff --git a/lib/devise_oauth2_authenticatable.rb b/lib/devise_oauth2_authenticatable.rb old mode 100644 new mode 100755 index e69de29..c0c9faa --- a/lib/devise_oauth2_authenticatable.rb +++ b/lib/devise_oauth2_authenticatable.rb @@ -0,0 +1,59 @@ +# encoding: utf-8 +require 'devise' +require 'oauth2' + + +require 'devise_oauth2_authenticatable/model' +require 'devise_oauth2_authenticatable/strategy' +require 'devise_oauth2_authenticatable/schema' +require 'devise_oauth2_authenticatable/routes' +#require 'devise_oauth2_authenticatable/controller_filters' +require 'devise_oauth2_authenticatable/view_helpers' + + +module Devise + # Specifies the name of the database column name used for storing + # the oauth UID. Useful if this info should be saved in a + # generic column if different authentication solutions are used. + mattr_accessor :oauth2_uid_field + @@oauth2_uid_field = :oauth2_uid + + # Specifies the name of the database column name used for storing + # the user Facebook session key. Useful if this info should be saved in a + # generic column if different authentication solutions are used. + mattr_accessor :oauth2_token_field + @@oauth2_token_field = :oauth2_token + + # Specifies if account should be created if no account exists for + # a specified Facebook UID or not. + mattr_accessor :oauth2_auto_create_account + @@oauth2_auto_create_account = true + + def self.oauth2_client + @@oauth2_client ||= OAuth2::Client.new(OAUTH2_CONFIG['client_id'], OAUTH2_CONFIG['client_secret'], :site => OAUTH2_CONFIG['authorization_server']) + end + + + def self.session_sign_in_url(request, mapping) + url = URI.parse(request.url) + url.path = "#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}" + url.query = nil + url.to_s + end + + def self.requested_scope + @@requested_scope ||= OAUTH2_CONFIG['requested_scope'] + end + +end + +# Load core I18n locales: en +# +I18n.load_path.unshift File.join(File.dirname(__FILE__), *%w[devise_oauth2_authenticatable locales en.yml]) + +# Add +:facebook_connectable+ strategies to defaults. +# +Devise.add_module(:oauth2_authenticatable, + :strategy => true, + :controller => :sessions, + :model => 'devise_oauth2_authenticatable/model') \ No newline at end of file diff --git a/spec/devise_oauth2_authenticatable_spec.rb b/spec/devise_oauth2_authenticatable_spec.rb old mode 100644 new mode 100755 diff --git a/spec/spec.opts b/spec/spec.opts old mode 100644 new mode 100755 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb old mode 100644 new mode 100755