userbin 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bdd5a2e5b60112f95a92dae7500b03dbea87ee9
4
- data.tar.gz: 4766121c403480224819add35e1c65e8b37666d9
3
+ metadata.gz: 7b561838ff6f87c720146c20d9817b0db06b8ff2
4
+ data.tar.gz: 3ecd413667cffa28272e8f7563ea1009b0057bfb
5
5
  SHA512:
6
- metadata.gz: ceebaf8f995b7adc429b83601dead50efea180b7f2410bad462752b548b9402ef5d5ffd1af2840cf763e7cdd593e8edfca0b4fffdc064e3e14d506acdacfb9b3
7
- data.tar.gz: 042c0a0bcad92c24e50c05b6adc0929c72736bc0fc75a860b3aa2e63060ea4a08745171dd6985ca1d5bd57656d34140067ca6177768f9d944e090f43c86aa663
6
+ metadata.gz: 9b7af19543462d9cb59d5f3060c3fafb91a529b06832d34aa43b52957a6b98b878694028ea75e428fcb5553686f976211ce4aa08b47b51457c49ee3cde9eb7a8
7
+ data.tar.gz: 33a11c347a277150e55f581b2cab91a4328b241aa2bd8758081cf11f784d1c97af5a9e3c8b8621e1a6cb7c0124a1ca758fffaeebcabbdb653a8e5fb8fbf24cc8
data/README.md CHANGED
@@ -1,33 +1,47 @@
1
- Userbin Ruby gem
1
+ Userbin for Ruby
2
2
  ================
3
3
 
4
+ Userbin for Ruby adds user authentication, login flows and user management to your **Rails**, **Sinatra** or **Rack** app.
5
+
6
+ [Userbin](https://userbin.com) provides a set of login, signup, and password reset forms that drop right into your application without any need of styling or writing markup. Connect your users via traditional logins or third party social networks. We take care of linking accounts across networks, resetting passwords, and keeping everything safe and secure. [Create a free account](https://userbin.com) to start accepting users in your application.
7
+
4
8
  Installation
5
9
  ------------
6
10
 
7
- Begin with signing up at [https://userbin.com](https://userbin.com) to obtain
8
- your App ID and API secret.
11
+ 1. Add the `userbin` gem to your `Gemfile`
9
12
 
10
- For simplicity’s sake, we will use the [Sinatra](http://www.sinatrarb.com/) framework. Start by installing Userbin and Sinatra:
13
+ ```ruby
14
+ gem "userbin"
15
+ ```
11
16
 
12
- ```bash
13
- $ gem install sinatra userbin
14
- ```
17
+ 1. Install the gem
15
18
 
16
- Now create a file called app.rb, require the gems and configure Userbin.
19
+ ```shell
20
+ bundle install
21
+ ```
22
+
23
+ 2. Configure the Userbin module with the credentials you got from signing up.
17
24
 
18
- Set up your restricted path to which users will be redirected on a successful logins. Browsing to this path or a sub-path will require the user to login. Logging out redirects the user back to the root path.
25
+ In a Rails app, put the following code into a new file at `config/initializers/userbin.rb`
19
26
 
20
- ```ruby
21
- # app.rb
22
- require "sinatra"
23
- require "userbin"
27
+ ```ruby
28
+ Userbin.configure do |config|
29
+ config.app_id = "YOUR_APP_ID"
30
+ config.api_secret = "YOUR_API_SECRET"
31
+ config.restricted_path = "/admin"
32
+ end
33
+ ```
24
34
 
25
- Userbin.app_id = "15_DIGIT_APP_ID"
26
- Userbin.api_secret = "32_BYTE_API_SECRET"
35
+ If you don't configure the `app_id` and `api_secret`, the Userbin module will read the `USERBIN_APP_ID` and `USERBIN_API_SECRET` environment variables. This may come in handy on Heroku.
36
+
37
+ Set up your `restricted_path` to which users will be redirected on a successful login. Browsing to this path or a sub-path will require the user to login. Logging out redirects the user back to the root path.
27
38
 
28
- use Userbin::Authentication, restricted_path: '/admin'
29
- ```
39
+ 3. **Rack/Sinatra apps only**: Activate the Userbin Rack middleware
30
40
 
41
+ ```ruby
42
+ use Userbin::Authentication
43
+ ```
44
+
31
45
  That's it! People are now able sign up and log in to your application.
32
46
 
33
47
  Usage
@@ -35,15 +49,15 @@ Usage
35
49
 
36
50
  ### Signup, login and logout
37
51
 
38
- To make installation as easy as possible, markup required for the Userbin UI are automatically inserted before the closing </body> and </head> tags in your HTML. It is therefore important that these tags are present on all pages where you want to use the links below.
52
+ NOTE: To make installation as easy as possible, markup required for the Userbin UI are automatically inserted before the closing </body> and </head> tags in your HTML. It is therefore important that these tags are present on all pages where you want to use the links below.
39
53
 
40
54
  These links will open up the [Userbin Widget](https://userbin.com/docs/javascript#widget) with either the login or signup form.
41
55
 
42
56
  ```html
43
57
  <!-- put this on a public page -->
44
- <a class="ub-login">Login</a>
58
+ <a class="ub-login">Log in</a>
45
59
  or
46
- <a class="ub-signup">Signup</a>
60
+ <a class="ub-signup">Sign up</a>
47
61
  ```
48
62
 
49
63
  The logout link will clear the session and redirect the user back to your root path:
@@ -6,14 +6,13 @@ module Userbin
6
6
 
7
7
  def initialize(app, options = {})
8
8
  @app = app
9
- @restricted_path = options[:restricted_path]
10
9
  end
11
10
 
12
11
  def call(env)
13
12
  request = Rack::Request.new(env)
14
13
 
15
14
  begin
16
- if env["REQUEST_PATH"] == "/userbin" &&
15
+ if env["PATH_INFO"] == "/userbin" &&
17
16
  env["REQUEST_METHOD"] == "POST"
18
17
  signature, data = Userbin.authenticate_events!(request)
19
18
 
@@ -26,7 +25,7 @@ module Userbin
26
25
  else
27
26
  signature, data = Userbin.authenticate!(request)
28
27
 
29
- if restrict && env["REQUEST_PATH"].start_with?(restrict) &&
28
+ if restrict && env["PATH_INFO"].start_with?(restrict) &&
30
29
  !Userbin.authenticated?
31
30
  return render_gateway(env["REQUEST_PATH"])
32
31
  end
@@ -51,7 +50,7 @@ module Userbin
51
50
  end
52
51
 
53
52
  def restrict
54
- Userbin.config.restricted_path || @restricted_path
53
+ Userbin.config.restricted_path
55
54
  end
56
55
 
57
56
  def link_tags(login_path)
@@ -82,13 +81,13 @@ module Userbin
82
81
  <head>
83
82
  <title>Log in</title>
84
83
  </head>
85
- <body style="background-color: #DBDBDB;">
84
+ <body>
86
85
  <a class="ub-login-form"></a>
87
86
  </body>
88
87
  </html>
89
88
  LOGIN_PAGE
90
89
  login_page = inject_tags(login_page, current_path)
91
- [ 200,
90
+ [ 403,
92
91
  { 'Content-Type' => 'text/html',
93
92
  'Content-Length' => login_page.length.to_s },
94
93
  [login_page]
@@ -115,8 +114,10 @@ module Userbin
115
114
  body = response
116
115
  end
117
116
 
118
- body = body.each.map do |chunk|
119
- inject_tags(chunk)
117
+ if Userbin.config.auto_include_tags
118
+ body = body.each.map do |chunk|
119
+ inject_tags(chunk)
120
+ end
120
121
  end
121
122
 
122
123
  if response.respond_to?(:body)
@@ -124,8 +125,6 @@ module Userbin
124
125
  else
125
126
  response = body
126
127
  end
127
-
128
- headers['Content-Length'] = body.join.length.to_s
129
128
  end
130
129
 
131
130
  if signature && data
@@ -2,7 +2,15 @@ module Userbin
2
2
  class Configuration
3
3
  attr_accessor :app_id
4
4
  attr_accessor :api_secret
5
+ attr_accessor :auto_include_tags
5
6
  attr_accessor :user_model
6
7
  attr_accessor :restricted_path
8
+
9
+ def initialize
10
+ self.app_id = ENV["USERBIN_APP_ID"]
11
+ self.api_secret = ENV["USERBIN_API_SECRET"]
12
+
13
+ self.auto_include_tags = true
14
+ end
7
15
  end
8
16
  end
@@ -0,0 +1,16 @@
1
+ module Userbin
2
+ module AuthHelpers
3
+ def userbin_current_user
4
+ local_id = Userbin.current_user.local_id
5
+
6
+ if local_id
7
+ user_klass = if Userbin.config.user_model
8
+ Userbin.config.user_model.call
9
+ else
10
+ User
11
+ end
12
+ @current_user ||= user_klass.find(local_id)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,13 @@
1
- module UserbinRails
1
+ require 'userbin/rails/auth_helpers'
2
+
3
+ module Userbin
4
+ ActiveSupport.on_load(:action_controller) do
5
+ include AuthHelpers
6
+ end
7
+
2
8
  class Railtie < Rails::Railtie
3
9
  initializer "userbin" do |app|
10
+ ActionView::Base.send :include, AuthHelpers
4
11
  app.config.middleware.use "Userbin::Authentication"
5
12
  end
6
13
  end
@@ -1,3 +1,3 @@
1
1
  module Userbin
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userbin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan
@@ -92,6 +92,7 @@ files:
92
92
  - lib/userbin/configuration.rb
93
93
  - lib/userbin/current.rb
94
94
  - lib/userbin/events.rb
95
+ - lib/userbin/rails/auth_helpers.rb
95
96
  - lib/userbin/railtie.rb
96
97
  - lib/userbin/session.rb
97
98
  - lib/userbin/userbin.rb
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  version: '0'
122
123
  requirements: []
123
124
  rubyforge_project:
124
- rubygems_version: 2.0.3
125
+ rubygems_version: 2.0.6
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Userbin