firebase_token_generator 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/firebase_token_generator.rb +25 -4
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDUzZTc0ZmMxMmNkODUxMjg3ODdkNWMzYWUzYzQ0MzY5OTlkZTYyNg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db673d7e0ac2d841a97401e6f16c82d02b21534c
|
4
|
+
data.tar.gz: 90d07595be2e4942590343fc7f3f3eee4ac98bbf
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NmJiYWUwMTUxMjI4YjkxODk1NDMwYzNiMGQ4ODEwY2Q3MDZmNjFiMzY1ZGU3
|
11
|
-
ZDllNmY5ZTgwYWM5NWZlZGYwY2UzMWE4NWRjOTk0OWMxNWI2MTY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YTMzMjlkNTU2MzVlY2Q2OTU3ZjUwMjVjNDRhY2QyZWMxNTEwNzdkZmMyY2U1
|
14
|
-
OWFhMjhlMjgwYjJlN2RmYmM3MjJlMGQ0MDJkNzUwNmFlOGE1YjU0ZmIwODM3
|
15
|
-
MDEzZmMzYmYwNDYyN2Y1YzVkZGM1MzY5YTJhYzY2MTM4ZTNmOWY=
|
6
|
+
metadata.gz: b532c83af441885c41d925be9d86d5a90b1b139f04d2e83b4daefc5efeba7188a182818574ea335d122e291b41a75414ad85ed3bbd879cc350af4285690bbed1
|
7
|
+
data.tar.gz: eec88f1f016a247293b7c8e450cf7edfe405d0ba51a929799a435de995d848947d368b5970c1693094f3561bf6c027fcd66d818fecf8e998a8152c27a25acd16
|
@@ -11,6 +11,9 @@ module Firebase
|
|
11
11
|
|
12
12
|
# When creating an instance of the generator, you must provide your Firebase Application Secret
|
13
13
|
def initialize(secret)
|
14
|
+
if (!secret.is_a?(String))
|
15
|
+
raise ArgumentError, "FirebaseTokenGenerator: secret must be a string."
|
16
|
+
end
|
14
17
|
@secret = secret
|
15
18
|
end
|
16
19
|
|
@@ -24,16 +27,22 @@ module Firebase
|
|
24
27
|
# [debug] If set to true, this client will receive debug information about the security rules
|
25
28
|
# [simulate] (internal-only for now) Runs security rules but makes no data changes
|
26
29
|
#
|
27
|
-
# Throws ArgumentError if given an invalid option
|
30
|
+
# Throws ArgumentError if given invalid data or an invalid option
|
31
|
+
# Throws RuntimeError if generated token is too long
|
28
32
|
def create_token(auth_data, options = {})
|
29
|
-
if auth_data.empty? and options.empty?
|
33
|
+
if (auth_data.nil? or auth_data.empty?) and (options.nil? or options.empty?)
|
30
34
|
raise ArgumentError, "FirebaseTokenGenerator.create_token: data is empty and no options are set. This token will have no effect on Firebase."
|
31
35
|
end
|
36
|
+
validate_auth_data(auth_data, (!options.nil? and options[:admin] == true))
|
32
37
|
claims = create_options_claims(options)
|
33
38
|
claims[:v] = TOKEN_VERSION
|
34
39
|
claims[:iat] = Time.now.to_i
|
35
40
|
claims[:d] = auth_data
|
36
|
-
encode_token(claims)
|
41
|
+
token = encode_token(claims)
|
42
|
+
if (token.length > 1024)
|
43
|
+
raise RuntimeError, "FirebaseTokenGenerator.create_token: generated token is too long."
|
44
|
+
end
|
45
|
+
token
|
37
46
|
end
|
38
47
|
|
39
48
|
private
|
@@ -50,6 +59,18 @@ module Firebase
|
|
50
59
|
:simulate => :simulate
|
51
60
|
}
|
52
61
|
|
62
|
+
def validate_auth_data(auth_data, is_admin_token)
|
63
|
+
if (!auth_data.nil? && !auth_data.is_a?(Hash))
|
64
|
+
raise ArgumentError, "FirebaseTokenGenerator.create_token: auth data must be a hash"
|
65
|
+
end
|
66
|
+
contains_uid = (!auth_data.nil? and auth_data.has_key?(:uid))
|
67
|
+
if ((!contains_uid and !is_admin_token) or (contains_uid and !auth_data[:uid].is_a?(String)))
|
68
|
+
raise ArgumentError, "FirebaseTokenGenerator.create_token: auth data must contain a :uid key that must be a string."
|
69
|
+
elsif (contains_uid and (auth_data[:uid].length > 256))
|
70
|
+
raise ArgumentError, "FirebaseTokenGenerator.create_token: auth data must contain a :uid key that must not be longer than 256 bytes."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
53
74
|
def create_options_claims(options)
|
54
75
|
opts = {}
|
55
76
|
options.each do |key, value|
|
@@ -59,7 +80,7 @@ module Firebase
|
|
59
80
|
if CLAIMS_MAP.include?(key.to_sym) then
|
60
81
|
opts[CLAIMS_MAP[key.to_sym]] = value
|
61
82
|
else
|
62
|
-
raise ArgumentError, "#{key.to_s} is not a valid option"
|
83
|
+
raise ArgumentError, "FirebaseTokenGenerator.create_token: #{key.to_s} is not a valid option"
|
63
84
|
end
|
64
85
|
end
|
65
86
|
opts
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase_token_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Soltis
|
8
|
+
- Chris Raynor
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
12
13
|
dependencies: []
|
13
14
|
description: A library for generating signed authentication tokens for use with Firebase.
|
14
15
|
Uses your app secret.
|
15
|
-
email:
|
16
|
+
email: support@firebase.com
|
16
17
|
executables: []
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
@@ -28,17 +29,17 @@ require_paths:
|
|
28
29
|
- lib
|
29
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
36
|
requirements:
|
36
|
-
- -
|
37
|
+
- - ">="
|
37
38
|
- !ruby/object:Gem::Version
|
38
39
|
version: '0'
|
39
40
|
requirements: []
|
40
41
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.1
|
42
|
+
rubygems_version: 2.4.1
|
42
43
|
signing_key:
|
43
44
|
specification_version: 4
|
44
45
|
summary: Generate Firebase Authentication Tokens
|