-
-
Notifications
You must be signed in to change notification settings - Fork 1
Authorization
You can use HTTPManagerRequest.oauth2()
to create a local OAuth 2.0 redirect server that captures the data. When you call OAuth2.start()
, it internally uses OS.shell_open()
to open the URL in your browser and listen requests to the redirect URI.
Note: The OAuth 2.0 server implementation is intended for personal applications. You must not share your client credentials across applications.
func auth() -> Error:
var route: HTTPManagerRoute = load("res://path/to/route/auth.tres")
return route.create_request({
a_url_query_param = "hello",
}).oauth2().start({
on_complete = _on_auth_completed, # On complete listener (Callable with response param)
timeout = 60.0, # Default value, you can omit
})
route
has a client with credentials in client.ini
(see Client Data). The file must contain:
[client]
id="1234"
secret="abcd"
Also, you must set OAuth2 Code as auth type and token-type route in auth_route
.
When OAuth 2.0 token is received, it is added to the file:
[token]
access_token="1234"
refresh_token="abcd"
expires_in=1000
token_type="Bearer"
Ensure all the keys are here and your routes have OAUTH2_CHECK
as auth_type
and a code-type auth_route
to work well. You can create an issue if you find other cases. I didn't find other case different to Bearer token.
You could duplicate a route to create routes with some properties set.
You can add a random state
url param using OAuth2.set_state()
chain method. You can set length with optional param (default value is 100
).
OAuth2.set_pkce()
is a chain method to add PKCE code verifier and code challenge in the URL. It supports "plain"
and "S256"
methods.