You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+13-10
Original file line number
Diff line number
Diff line change
@@ -20,18 +20,20 @@ Libraries that deal with authentication can be divided into two parts:
20
20
- the providers: the ones that perform the authentication and provide tokens. Example: [Google Cloud Rust][link-google-cloud-rust].
21
21
- the consumers: the ones that require you to provide tokens for their usage. Example: [Reqwest][link-reqwest], [Openapi Generator][link-openapi-generator].
22
22
23
-
Unfortunately, nothing really unify these two category of libraries.
23
+
Unfortunately, nothing really unify these two categories of library.
24
24
Also, because some libraries may provide you very limited way to manage the tokens, it often leave you the responsibility to bridge the gap between the two.
25
25
26
26
**Example 1**
27
+
27
28
You are deploying a service in Kubernetes (let's say GKE) and this servive need to request another one.
28
29
- the external service provides a rust client library, automatically generated via [Openapi Generator][link-openapi-generator]. This requires to set the authentication as a `string` when creating the client.
29
30
- use [Google Cloud Rust][link-google-cloud-rust] or any other crate providing similar features to get a valid authentication token.
30
31
31
32
It will come a time where a generated token will expire (especially short-time ones) and you probably do not want to create a new client instance for every request your need to perform to the external service.
32
-
Here, because of the lack of functionalities/authentication mechanism support from the generate library, you have no choice than dealing with the token expiry verification and renewal by yourself, re-creating a new client.
33
+
Here, because of the lack of functionalities/authentication mechanism support from the generated library, you have no other choice than dealing with the token expiry verification and renewal by yourself, re-creating a new client.
33
34
34
35
**Example 2**
36
+
35
37
You are deploying a service in Kubernetes (let's say GKE) and this service need to request another one.
36
38
You may use:
37
39
- use [Reqwest][link-reqwest] to query the external service, providing a token as a `string` put in the headers.
@@ -41,20 +43,21 @@ You may use:
41
43
Everything may goes well, until one of your request get triggered very close to the expiry time of your already generated token and that request fails and get retries for some reason. When the retry policy applys, the authentication token will expire and the subsequent retries will all fails due to `403`
42
44
43
45
**Example 3**
46
+
44
47
Same as example 2, but let says that you now want to deploy your service in both GKE and EKS.
45
48
You will have to provide two different way of sourcing the authentication tokens. You can use any technic (based on environment settings, based on compilation profiles) but your will certainly have to write some code to deal with this, and that can be pretty boiler plate depending on the libraries you will use.
46
49
47
-
### One crate to standardize them all!
48
-
49
-
Having a single crate defining simple definitions of `token-source` and `token-source-provider` as Trait will help to standardize expectations, behavior and responsibilities across libraries.
50
+
### One crate to standardize them all
50
51
51
-
Of course, this will be proven true as libraries start using those trait as their requirements, rather than pure `string` or custom types.
52
+
Having a single crate with simple definitions of `token-source` and `token-source-provider` as Trait will help to standardize expectations, behavior and responsibilities across libraries.
52
53
54
+
As other libraries start to use the `TokenSource` and `TokenSourceProvider` traits in place of raw of custom types, it will become easier to use it.
0 commit comments