-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mandatory validation check of twitch. Adjusted the login proces…
…s so that it doesn't spam Twitch alot and helps the user to find the problem with their authroization
- Loading branch information
Showing
4 changed files
with
65 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
extends "res://addons/twitcher/lib/oOuch/token_handler.gd" | ||
|
||
class_name TwitchTokenHandler | ||
|
||
## Time between checking the validation of the tokens | ||
var _last_validation_check: int = 0 | ||
|
||
func _check_token_refresh() -> void: | ||
super._check_token_refresh() | ||
|
||
if _last_validation_check < Time.get_ticks_msec(): | ||
_last_validation_check = Time.get_ticks_msec() + 60 * 60 * 1000; | ||
_validate_token() | ||
|
||
## Calles the validation endpoint of Twtich to make sure | ||
func _validate_token() -> void: | ||
var validation_request = _http_client.request("/oauth2/validate", HTTPClient.METHOD_GET, { | ||
"Authorization": "OAuth %s" % _tokens.get_access_token() | ||
}, "") | ||
var response = await _http_client.wait_for_request(validation_request) | ||
if response.response_code != 200: | ||
refresh_tokens() | ||
return | ||
|
||
var response_string: String = response.response_data.get_string_from_utf8(); | ||
var response_data = JSON.parse_string(response_string); | ||
if response_data["expires_in"] <= 0: | ||
refresh_tokens() | ||
return |