Skip to content
Browse files

give access to auth hash as instance method

  • Loading branch information...
1 parent 024a33f commit abe3a38c8f017167385f1c724b356c0a953bbbf2 @kurenn kurenn committed Mar 27, 2013
View
34 README.md
@@ -1,6 +1,6 @@
#Ninsho
-Ninsho is easy flexible authentication solution when using providers
+Ninsho is an easy flexible authentication solution when using providers
* Is a complete MVC solution based on Rails Engines;
* Works with most providers out there, Github, Facebook, Twitter, Linkedin
@@ -109,6 +109,34 @@ And after that if you want ninsho to respond to that, you just need to add the p
config.omniauth :facebook, "APP_ID", "APP_SECRET", :scope => 'email'
```
+###Custom fields
+
+Now you have access to the hash provided by any of the omniauth providers gem, as an instance method under:
+
+```ruby
+self.auth_hash
+```
+
+So if you need to add an extra field to your ninsho model (commonly 'Authentication'), it's as easy as adding a ```before_save``` callback and handle the extra stuff by yourself. Don't get it?, here ir a quick example:
+
+Let's say we want to save the nickname from the hash into our ninsho model:
+
+1. Add the migration to the ninsho model
+ ```console
+ rails g migration add_nickname_to_MODEL nickname:string
+ ```
+2. Run the migration and add the callback which should look like:
+```ruby
+before_save :set_nickname
+```
+```ruby
+def set_nickname
+ self.nickname = self.auth_hash.info.nickname
+end
+```
+3. You are good to go, and any time the user changes the nickname yours will too!
+
+
### I18n
You can overwrite the ninsho locale and customize the flash messages:
@@ -126,6 +154,7 @@ en:
* Current gem version 0.0.3
* Add more documentation on code
* Add aouth token for Facebook friends
+* Add more flexibility to handle authentications and save to multiple fields
* Add handy helpers
* Released gem version 0.0.2
* Released gem version 0.0.1
@@ -136,9 +165,10 @@ en:
### Future
-* Add more flexibility to handle authentications and save multiple to fields
* Add tests
* Support for Mongoid
+* Add wiki
+* Add rails live example
## Credits
View
2 app/controllers/ninsho_controller.rb
@@ -46,7 +46,7 @@ def parent_resource
# Build a ninsho resource, from the omniauth hash
def build_resource_from_omniauth
- self.resource = resource_class.from_omniauth(resource_params)
+ self.resource = resource_class.from_omniauth(resource_params)
end
end
View
2 lib/generators/active_record/ninsho_generator.rb
@@ -23,7 +23,7 @@ def generate_model
def inject_ninsho_content
content = <<CONTENT
- attr_accessible :provider, :uid
+ attr_accessible :provider, :uid, :oauth_token
# belongs_to_ninsho :user
CONTENT
View
11 lib/ninsho/interface.rb
@@ -6,8 +6,14 @@ def self.included(base)
base.extend(ClassMethods)
end
+ def auth_hash
+ Ninsho.resource_class.auth_hash
+ end
+
module ClassMethods
-
+
+ attr_accessor :auth_hash
+
def belongs_to_ninsho(*args)
options = args.extract_options!
@@ -20,10 +26,11 @@ def belongs_to_ninsho(*args)
Ninsho.parent_resource_name = Ninsho.ref(associated_model.to_s.classify).get
end
end
-
+
# Responsible for creating or find the record with the
# omniauth hash
def from_omniauth(omniauth = nil)
+ self.auth_hash = omniauth
Ninsho::Authentication.new(omniauth)
end
end
View
2 lib/ninsho/version.rb
@@ -1,3 +1,3 @@
module Ninsho
- VERSION = "0.0.3"
+ VERSION = "0.1.0"
end

0 comments on commit abe3a38

Please sign in to comment.
Something went wrong with that request. Please try again.