twilioauth 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -2
- data/lib/twilioauth.rb +1 -69
- data/twilioauth.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -8,11 +8,48 @@ Usage
|
|
8
8
|
|
9
9
|
``` ruby
|
10
10
|
require "twilioauth"
|
11
|
-
|
11
|
+
pin = Twilioauth.auth("+15555555555", :account_sid => "*************", :auth_token => "****************")
|
12
12
|
```
|
13
13
|
|
14
|
+
Simple example with controller methods.
|
15
|
+
|
16
|
+
``` ruby
|
17
|
+
|
18
|
+
def login
|
19
|
+
#login has succeeded and now need to check pin
|
20
|
+
session[:pin] = Twilioauth.auth(@user.phone, :account_sid => "**********", :auth_token => "**********")
|
21
|
+
session[:pendinguser] = {name: params[:name], password: params[:password]}
|
22
|
+
redirect_to "/auth"
|
23
|
+
end
|
24
|
+
|
25
|
+
def auth
|
26
|
+
#form to enter pin here and submits to check_auth
|
27
|
+
unless session[:pendinguser]
|
28
|
+
redirect_to "/login"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_auth
|
33
|
+
#if the pin is the same set the user session
|
34
|
+
if params[:pin] == session[:pin]
|
35
|
+
session[:user] = session[:pendinguser]
|
36
|
+
redirect_to "/success"
|
37
|
+
else
|
38
|
+
redirect_to "/login?pin_failed=true"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
TODO
|
44
|
+
----
|
45
|
+
|
46
|
+
Roll twilioauth into a rails engine with controllers and forms to handle everything for the developer.
|
47
|
+
|
14
48
|
History
|
15
49
|
----------
|
50
|
+
0.0.5 removed a lot of unnecessary random charcter code.
|
51
|
+
|
52
|
+
0.0.4 first working version for rails integration
|
16
53
|
|
54
|
+
0.0.1 first working sms auth.
|
17
55
|
|
18
|
-
0.0.1 first working sms auth.
|
data/lib/twilioauth.rb
CHANGED
@@ -27,77 +27,9 @@ module Twilioauth
|
|
27
27
|
|
28
28
|
def self.auth(number, options = {})
|
29
29
|
connection = Twilioauth::Connection.new(options[:account_sid], options[:auth_token])
|
30
|
-
newpin =
|
30
|
+
newpin = SecureRandom.hex(3)
|
31
31
|
connection.sms(newpin, number)
|
32
32
|
return newpin
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.random_bytes(n=nil)
|
36
|
-
n ||= 16
|
37
|
-
|
38
|
-
unless defined? OpenSSL
|
39
|
-
begin
|
40
|
-
require 'openssl'
|
41
|
-
rescue LoadError
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
if defined? OpenSSL::Random
|
46
|
-
return OpenSSL::Random.random_bytes(n)
|
47
|
-
end
|
48
|
-
|
49
|
-
if !defined?(@has_urandom) || @has_urandom
|
50
|
-
flags = File::RDONLY
|
51
|
-
flags |= File::NONBLOCK if defined? File::NONBLOCK
|
52
|
-
flags |= File::NOCTTY if defined? File::NOCTTY
|
53
|
-
flags |= File::NOFOLLOW if defined? File::NOFOLLOW
|
54
|
-
begin
|
55
|
-
File.open("/dev/urandom", flags) {|f|
|
56
|
-
unless f.stat.chardev?
|
57
|
-
raise Errno::ENOENT
|
58
|
-
end
|
59
|
-
@has_urandom = true
|
60
|
-
ret = f.readpartial(n)
|
61
|
-
if ret.length != n
|
62
|
-
raise NotImplementedError, "Unexpected partial read from random device"
|
63
|
-
end
|
64
|
-
return ret
|
65
|
-
}
|
66
|
-
rescue Errno::ENOENT
|
67
|
-
@has_urandom = false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
if !defined?(@has_win32)
|
72
|
-
begin
|
73
|
-
require 'Win32API'
|
74
|
-
|
75
|
-
crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L')
|
76
|
-
@crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L')
|
77
|
-
|
78
|
-
hProvStr = " " * 4
|
79
|
-
prov_rsa_full = 1
|
80
|
-
crypt_verifycontext = 0xF0000000
|
81
|
-
|
82
|
-
if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0
|
83
|
-
raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
|
84
|
-
end
|
85
|
-
@hProv, = hProvStr.unpack('L')
|
86
|
-
|
87
|
-
@has_win32 = true
|
88
|
-
rescue LoadError
|
89
|
-
@has_win32 = false
|
90
|
-
end
|
91
|
-
end
|
92
|
-
if @has_win32
|
93
|
-
bytes = " " * n
|
94
|
-
if @crypt_gen_random.call(@hProv, bytes.size, bytes) == 0
|
95
|
-
raise SystemCallError, "CryptGenRandom failed: #{lastWin32ErrorMessage}"
|
96
|
-
end
|
97
|
-
return bytes
|
98
|
-
end
|
99
|
-
|
100
|
-
raise NotImplementedError, "No random device"
|
101
|
-
end
|
102
|
-
|
103
35
|
end
|
data/twilioauth.gemspec
CHANGED