Skip to content

Commit 393c7cb

Browse files
committed
update v1.3
1 parent 92f788f commit 393c7cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2154
-1110
lines changed

addons/godot-firebase/auth/auth.gd

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ var _needs_refresh : bool = false
3636
var is_busy : bool = false
3737

3838
var _headers : PoolStringArray = [
39-
"Content-Type: application/json",
40-
# "Access-Control-Allow-Origin: *"
39+
"Accept: application/json"
4140
]
4241

4342
var requesting : int = -1
4443

45-
enum REQUESTS {
44+
enum Requests {
4645
NONE = -1,
4746
EXCHANGE_TOKEN,
4847
LOGIN_WITH_OAUTH,
@@ -196,7 +195,7 @@ func exchange_google_token(google_token : String) -> void:
196195
_google_token_body.code = google_token
197196
_google_token_body.client_id = _config.clientId
198197
_google_token_body.client_secret = _config.clientSecret
199-
requesting = REQUESTS.EXCHANGE_TOKEN
198+
requesting = Requests.EXCHANGE_TOKEN
200199
request(_google_token_request_url, _headers, true, HTTPClient.METHOD_POST, JSON.print(_google_token_body))
201200

202201
# Login with Google oAuth2.
@@ -209,7 +208,7 @@ func login_with_oauth(google_token: String, provider_id : String = "google.com",
209208
is_busy = true
210209
_oauth_login_request_body.postBody = _post_body.replace("[GOOGLE_ID_TOKEN]", auth.idtoken).replace("[PROVIDER_ID]", provider_id)
211210
_oauth_login_request_body.requestUri = _request_uri.replace("[REQUEST_URI]", request_uri)
212-
requesting = REQUESTS.LOGIN_WITH_OAUTH
211+
requesting = Requests.LOGIN_WITH_OAUTH
213212
request(_signin_with_oauth_request_url, _headers, true, HTTPClient.METHOD_POST, JSON.print(_oauth_login_request_body))
214213

215214
# Function used to logout of the system, this will also remove the local encrypted auth file if there is one
@@ -246,7 +245,7 @@ func _on_FirebaseAuth_request_completed(result : int, response_code : int, heade
246245
if not res.has("kind"):
247246
auth = get_clean_keys(res)
248247
match requesting:
249-
REQUESTS.EXCHANGE_TOKEN:
248+
Requests.EXCHANGE_TOKEN:
250249
emit_signal("token_exchanged", true)
251250
begin_refresh_countdown()
252251
else:
@@ -264,12 +263,12 @@ func _on_FirebaseAuth_request_completed(result : int, response_code : int, heade
264263
emit_signal("userdata_received", userdata)
265264
else:
266265
# error message would be INVALID_EMAIL, EMAIL_NOT_FOUND, INVALID_PASSWORD, USER_DISABLED or WEAK_PASSWORD
267-
if requesting == REQUESTS.EXCHANGE_TOKEN:
266+
if requesting == Requests.EXCHANGE_TOKEN:
268267
emit_signal("token_exchanged", false)
269268
emit_signal("login_failed", res.error, res.error_description)
270269
else:
271270
emit_signal("login_failed", res.error.code, res.error.message)
272-
requesting = REQUESTS.NONE
271+
requesting = Requests.NONE
273272

274273
# Function used to save the auth data provided by Firebase into an encrypted file
275274
# Note this does not work in HTML5 or UWP
@@ -329,7 +328,7 @@ func change_user_email(email : String) -> void:
329328
func change_user_password(password : String) -> void:
330329
if _is_ready():
331330
is_busy = true
332-
_change_password_body.email = password
331+
_change_password_body.password = password
333332
_change_password_body.idToken = auth.idtoken
334333
request(_update_account_request_url, _headers, true, HTTPClient.METHOD_POST, JSON.print(_change_password_body))
335334

addons/godot-firebase/database/database.gd

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,21 @@ tool
66
class_name FirebaseDatabase
77
extends Node
88

9-
const ORDER_BY : String = "orderBy"
10-
const LIMIT_TO_FIRST : String = "limitToFirst"
11-
const LIMIT_TO_LAST : String = "limitToLast"
12-
const START_AT : String = "startAt"
13-
const END_AT : String = "endAt"
14-
const EQUAL_TO : String = "equalTo"
9+
var _config : Dictionary = {}
1510

16-
var config : Dictionary = {}
17-
18-
var auth : Dictionary = {}
11+
var _auth : Dictionary = {}
1912

2013
func _set_config(config_json : Dictionary) -> void:
21-
config = config_json
14+
_config = config_json
2215

2316
func _on_FirebaseAuth_login_succeeded(auth_result : Dictionary) -> void:
24-
auth = auth_result
17+
_auth = auth_result
2518

2619
func _on_FirebaseAuth_token_refresh_succeeded(auth_result : Dictionary) -> void:
27-
auth = auth_result
20+
_auth = auth_result
21+
22+
func _on_FirebaseAuth_logout() -> void:
23+
_auth = {}
2824

2925
func get_database_reference(path : String, filter : Dictionary = {}) -> FirebaseDatabaseReference:
3026
var firebase_reference : FirebaseDatabaseReference = FirebaseDatabaseReference.new()
@@ -33,7 +29,7 @@ func get_database_reference(path : String, filter : Dictionary = {}) -> Firebase
3329
listener.set_script(load("res://addons/http-sse-client/HTTPSSEClient.gd"))
3430
var store : FirebaseDatabaseStore = FirebaseDatabaseStore.new()
3531
firebase_reference.set_db_path(path, filter)
36-
firebase_reference.set_auth_and_config(auth, config)
32+
firebase_reference.set_auth_and_config(_auth, _config)
3733
firebase_reference.set_pusher(pusher)
3834
firebase_reference.set_listener(listener)
3935
firebase_reference.set_store(store)

addons/godot-firebase/database/reference.gd

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ signal patch_data_update(data)
1212
signal push_successful()
1313
signal push_failed()
1414

15+
const ORDER_BY : String = "orderBy"
16+
const LIMIT_TO_FIRST : String = "limitToFirst"
17+
const LIMIT_TO_LAST : String = "limitToLast"
18+
const START_AT : String = "startAt"
19+
const END_AT : String = "endAt"
20+
const EQUAL_TO : String = "equalTo"
21+
1522
var _pusher : HTTPRequest
1623
var _listener : Node
1724
var _store : FirebaseDatabaseStore
@@ -37,9 +44,7 @@ const _escaped_quote : String = "\""
3744
const _equal_tag : String = "="
3845
const _key_filter_tag : String = "$key"
3946

40-
var _headers : PoolStringArray = [
41-
"Access-Control-Allow-Origin: *"
42-
]
47+
var _headers : PoolStringArray = []
4348

4449
func set_db_path(path : String, filter_query_dict : Dictionary) -> void:
4550
_db_path = path
@@ -130,12 +135,11 @@ func _get_filter():
130135
# At the moment, this means you can't dynamically change your filter; I think it's okay to specify that in the rules.
131136
if !_cached_filter:
132137
_cached_filter = ""
133-
if _filter_query.has(get_parent().ORDER_BY):
134-
_cached_filter += get_parent().ORDER_BY + _equal_tag + _escaped_quote + _filter_query[get_parent().ORDER_BY] + _escaped_quote
135-
_filter_query.erase(get_parent().ORDER_BY)
138+
if _filter_query.has(ORDER_BY):
139+
_cached_filter += ORDER_BY + _equal_tag + _escaped_quote + _filter_query[ORDER_BY] + _escaped_quote
140+
_filter_query.erase(ORDER_BY)
136141
else:
137-
_cached_filter += get_parent().ORDER_BY + _equal_tag + _escaped_quote + _key_filter_tag + _escaped_quote # Presumptuous, but to get it to work at all...
138-
142+
_cached_filter += ORDER_BY + _equal_tag + _escaped_quote + _key_filter_tag + _escaped_quote # Presumptuous, but to get it to work at all...
139143
for key in _filter_query.keys():
140144
_cached_filter += _filter_tag + key + _equal_tag + _filter_query[key]
141145

addons/godot-firebase/dynamiclinks/dynamiclinks.gd

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extends Node
99

1010
signal dynamic_link_generated(link_result)
1111

12-
const _authorization_header : String = "Authorization: Bearer "
12+
const _AUTHORIZATION_HEADER : String = "Authorization: Bearer "
1313

1414
var request : int = -1
1515

@@ -20,11 +20,9 @@ var _config : Dictionary = {}
2020
var _auth : Dictionary
2121
var _request_list_node : HTTPRequest
2222

23-
var _headers : PoolStringArray = [
24-
"Access-Control-Allow-Origin: *"
25-
]
23+
var _headers : PoolStringArray = []
2624

27-
enum REQUESTS {
25+
enum Requests {
2826
NONE = -1,
2927
GENERATE
3028
}
@@ -56,7 +54,7 @@ var _link_request_body : Dictionary = {
5654
## This function is used to generate a dynamic link using the Firebase REST API
5755
## It will return a JSON with the shortened link
5856
func generate_dynamic_link(long_link : String, APN : String, IBI : String, is_unguessable : bool) -> void:
59-
request = REQUESTS.GENERATE
57+
request = Requests.GENERATE
6058
_link_request_body.dynamicLinkInfo.domainUriPrefix = _config.domainUriPrefix
6159
_link_request_body.dynamicLinkInfo.link = long_link
6260
_link_request_body.dynamicLinkInfo.androidInfo.androidPackageName = APN
@@ -70,13 +68,13 @@ func generate_dynamic_link(long_link : String, APN : String, IBI : String, is_un
7068
func _on_request_completed(result : int, response_code : int, headers : PoolStringArray, body : PoolByteArray) -> void:
7169
var result_body : Dictionary = JSON.parse(body.get_string_from_utf8()).result
7270
emit_signal("dynamic_link_generated", result_body.shortLink)
73-
request = REQUESTS.NONE
71+
request = Requests.NONE
7472

7573
func _on_FirebaseAuth_login_succeeded(auth_result : Dictionary) -> void:
7674
_auth = auth_result
7775

7876
func _on_FirebaseAuth_token_refresh_succeeded(auth_result : Dictionary) -> void:
7977
_auth = auth_result
80-
81-
func _on_firebaseAuth_clear_auth():
78+
79+
func _on_FirebaseAuth_logout() -> void:
8280
_auth = {}

addons/godot-firebase/firebase/firebase.gd

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,9 @@ var _config : Dictionary = {
4747
"clientId": "",
4848
"clientSecret": "",
4949
"domainUriPrefix": "",
50+
"cacheLocation": "user://.firebase_cache"
5051
}
5152

52-
func _load_config() -> void:
53-
if ProjectSettings.has_setting(_ENVIRONMENT_VARIABLES+"apiKey"):
54-
for key in _config.keys():
55-
if ProjectSettings.get_setting(_ENVIRONMENT_VARIABLES+key)!="":
56-
_config[key] = ProjectSettings.get_setting(_ENVIRONMENT_VARIABLES+key)
57-
else:
58-
if _config[key] == "":
59-
printerr("Configuration key '{key}' not found!".format({key = key}))
60-
else:
61-
printerr("No configuration settings found, add them in override.cfg file.")
62-
6353
func _ready() -> void:
6454
_load_config()
6555
for module in get_children():
@@ -70,3 +60,15 @@ func _ready() -> void:
7060
Auth.connect("signup_succeeded", module, "_on_FirebaseAuth_login_succeeded")
7161
Auth.connect("token_refresh_succeeded", module, "_on_FirebaseAuth_token_refresh_succeeded")
7262
Auth.connect("logged_out", module, "_on_FirebaseAuth_logout")
63+
64+
func _load_config() -> void:
65+
if ProjectSettings.has_setting(_ENVIRONMENT_VARIABLES+"apiKey"):
66+
for key in _config.keys():
67+
var env_var : String = _ENVIRONMENT_VARIABLES + key
68+
if ProjectSettings.has_setting(env_var) and ProjectSettings.get_setting(env_var) != "":
69+
_config[key] = ProjectSettings.get_setting(env_var)
70+
else:
71+
if _config[key] == "":
72+
printerr("Configuration key '{key}' not found!".format({key = key}))
73+
else:
74+
printerr("No configuration settings found, add them in override.cfg file.")

0 commit comments

Comments
 (0)