minnie-omniauth 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ bin
6
+ vendor/bundle
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in minnie-omniauth.gemspec
4
+ gemspec
@@ -0,0 +1,48 @@
1
+ #Minnie-OmniAuth
2
+
3
+ minnie-omniauth is an authentication strategy for the [minnie gem](https://github.com/mm53bar/minnie).
4
+
5
+ ###First Things First
6
+
7
+ Make sure you know what you're doing with OmniAuth. Check out the Railscast at [http://railscasts.com/episodes/235-omniauth-part-1](http://railscasts.com/episodes/235-omniauth-part-1)
8
+
9
+ ###Install
10
+
11
+ All good with Omniauth. OK - let's get going.
12
+
13
+ Add minnie-omniauth to your Gemfile
14
+
15
+ gem 'minnie-omniauth'
16
+
17
+ Now follow the instructions for the minnie gem to run the generator. Here's a hint:
18
+
19
+ bundle exec rails generate minnie:install
20
+
21
+ Then run the minnie-omniauth installer to get a sessions_controller that works with OmniAuth:
22
+
23
+ bundle exec rails generate minnie-omniauth:install
24
+
25
+ Now generate a User model with this command:
26
+
27
+ bundle exec rails generate model User uid:string name:string username:string access_token:string access_token_secret:string
28
+
29
+ And update the generated User model so that your model looks like this:
30
+
31
+ class User < ActiveRecord::Base
32
+ include Minnie::User::Omniauth
33
+ end
34
+
35
+ Lastly, make sure you've set up your provider's callback in config/routes.rb:
36
+
37
+ match '/auth/:provider/callback', to: 'sessions#create'
38
+
39
+ Replace :provider with the name of the OmniAuth strategy you're using.
40
+
41
+ You're all done! Now try to sign in to your app at [/signin](http://localhost:3000/signin).
42
+
43
+ ###Issues
44
+
45
+ There isn't much code here so try resolving issues on your own. If you get some issues fixed, send me a pull request!
46
+
47
+ If you're not making any headway, just create an issue and I'll try to look at it.
48
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ module MinnieOmniauth
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ desc "Configures your app with a sessions_controller for Minnie-OmniAuth."
7
+
8
+ def copy_sessions_controller
9
+ copy_file "sessions_controller.rb", "app/controllers/sessions_controller.rb"
10
+ end
11
+
12
+ def show_readme
13
+ readme "README" if behavior == :invoke
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ ===============================================================================
2
+
3
+ Congratulations! You've now set up Minnie for your OmniAuth authentication.
4
+
5
+ If you're just starting out, here's a few more things you can do:
6
+
7
+ 1. Set up your User model for OmniAuth. Just add this to your User model:
8
+
9
+ class User < ActiveRecord::Base
10
+ include Minnie::User::Omniauth
11
+
12
+ 2. Ensure you have set up your provider's routes in config/routes.rb
13
+ For example:
14
+
15
+ match '/auth/:provider/callback', to: 'sessions#create'
16
+
17
+ 3. Update your user model to support the extra OmniAuth fields. Something
18
+ like this should work:
19
+
20
+ bundle exec rails g migration uid:string name:string username:string
21
+ access_token:string access_token_secret:string
22
+
23
+ Be careful with validations - only uid and name are in every
24
+ OmniAuth strategy.
25
+
@@ -0,0 +1,18 @@
1
+ class SessionsController < ApplicationController
2
+ skip_before_filter :authenticate_user!, :only => [:new, :create]
3
+
4
+ def create
5
+ @user = User.authenticate(auth_hash)
6
+ sign_in_and_redirect(@user)
7
+ end
8
+
9
+ def destroy
10
+ sign_out_and_redirect
11
+ end
12
+
13
+ protected
14
+
15
+ def auth_hash
16
+ request.env['omniauth.auth']
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require "minnie-omniauth/version"
2
+
3
+ module Minnie
4
+ module User
5
+ autoload :Omniauth, 'minnie-omniauth/user/omniauth'
6
+ end
7
+ end
8
+
@@ -0,0 +1,37 @@
1
+ module Minnie
2
+ module User
3
+ module Omniauth
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def authenticate(auth_hash)
8
+ if (user = self.first(conditions: {uid: auth_hash['uid']}))
9
+ user.assign_account_info(auth_hash)
10
+ user.save
11
+ user
12
+ else
13
+ create_from_auth_hash(auth_hash)
14
+ end
15
+ end
16
+
17
+ def create_from_auth_hash(auth_hash)
18
+ create do |user|
19
+ user.assign_account_info(auth_hash)
20
+ end
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def assign_account_info(auth_hash)
26
+ self.uid = auth_hash['uid']
27
+ self.name = auth_hash['info']['name']
28
+ self.username = auth_hash['info']['nickname'] if auth_hash['info']['nickname']
29
+ self.access_token = auth_hash['credentials']['token'] if auth_hash['credentials']['token']
30
+ self.access_token_secret = auth_hash['credentials']['secret'] if auth_hash['credentials']['secret']
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+
@@ -0,0 +1,5 @@
1
+ module Minnie
2
+ module Omniauth
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "minnie-omniauth/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "minnie-omniauth"
7
+ s.version = Minnie::Omniauth::VERSION
8
+ s.authors = ["Michael McClenaghan"]
9
+ s.email = ["mike@sideline.ca"]
10
+ s.homepage = "https://github.com/mm53bar/minnie-omniauth"
11
+ s.summary = %q{OmniAuth add-on to the simplest authentication possible}
12
+ s.description = %q{The simplest that OmniAuth authentication can get while still being useful}
13
+
14
+ s.rubyforge_project = "minnie-omniauth"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "minnie"
22
+ s.add_runtime_dependency "omniauth"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minnie-omniauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael McClenaghan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minnie
16
+ requirement: &70312385990580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70312385990580
25
+ - !ruby/object:Gem::Dependency
26
+ name: omniauth
27
+ requirement: &70312385989960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70312385989960
36
+ description: The simplest that OmniAuth authentication can get while still being useful
37
+ email:
38
+ - mike@sideline.ca
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/generators/minnie_omniauth/install_generator.rb
48
+ - lib/generators/minnie_omniauth/templates/README
49
+ - lib/generators/minnie_omniauth/templates/sessions_controller.rb
50
+ - lib/minnie-omniauth.rb
51
+ - lib/minnie-omniauth/user/omniauth.rb
52
+ - lib/minnie-omniauth/version.rb
53
+ - minnie-omniauth.gemspec
54
+ homepage: https://github.com/mm53bar/minnie-omniauth
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ segments:
67
+ - 0
68
+ hash: 804510902626202535
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: 804510902626202535
78
+ requirements: []
79
+ rubyforge_project: minnie-omniauth
80
+ rubygems_version: 1.8.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: OmniAuth add-on to the simplest authentication possible
84
+ test_files: []