-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2516cb0
commit fe12fe1
Showing
4 changed files
with
141 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Federated Token - Apollo Plugin | ||
|
||
[![npm](https://img.shields.io/npm/v/@labdigital/federated-token.svg)](https://www.npmjs.com/package/@labdigital/federated-token) | ||
|
||
This package provides support for both Apollo Server (including Gateway). It | ||
processes the token and forwards it to downstream services and also reads | ||
new/updated tokens from downstream services. | ||
|
||
It provides three Apollo specific classes: | ||
|
||
- `GatewayAuthPlugin` - An Apollo plugin for the GraphQL gateway that verifies | ||
the signature of the token passed and decrypts the embedded JWE property. It | ||
stores the verified and decrypted token on the context as `federatedToken`. | ||
|
||
- `FederatedGraphQLDataSource` - An Apollo GraphQL data source used in the | ||
GraphQL Gateway which passes the `federatedToken` from the context to the | ||
datasource (federated service) as `x-access-token` HTTP header. | ||
|
||
- `FederatedAuthPlugin` - An Apollo plugin for federated services that reads | ||
the token passed in the `x-access-token` header and stores it on the context | ||
as `federatedToken`. | ||
|
||
When a federated services creates a new token (when non exist) it can also | ||
return a refresh token in the `x-refresh-token` header. The gateway will then | ||
encrypt all refresh tokens and encrypt them before passing them to the client | ||
as `x-refresh-token` header. |
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,17 @@ | ||
# Federated Token - Envelop Plugin | ||
|
||
[![npm](https://img.shields.io/npm/v/@labdigital/federated-token.svg)](https://www.npmjs.com/package/@labdigital/federated-token) | ||
|
||
This packages provides an Envelop plugin so that for example Yoga can be used as | ||
a federated service. I | ||
|
||
It provides three Apollo specific classes: | ||
|
||
- `federatedAuthPlugin` - An Apollo plugin for federated services that reads | ||
the token passed in the `x-access-token` header and stores it on the context | ||
as `federatedToken`. | ||
|
||
When a federated services creates a new token (when non exist) it can also | ||
return a refresh token in the `x-refresh-token` header. The gateway will then | ||
encrypt all refresh tokens and encrypt them before passing them to the client | ||
as `x-refresh-token` header. |
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,44 @@ | ||
# Federated Token - React Provider | ||
|
||
The package `@labdigital/federated-token-react` provides a React context provider | ||
to manage the token state in a React application. | ||
|
||
# Usage | ||
|
||
Register the `AuthProvider` in your application. This will provide the token to | ||
all components in the application. | ||
|
||
```tsx | ||
import { | ||
AuthProvider, | ||
AuthProviderProps, | ||
} from "@labdigital/federated-token-react"; | ||
|
||
const authProviderProps: AuthProviderProps = { | ||
logoutMutation: JSON.stringify({ | ||
query: "mutation { clearToken }", | ||
}), | ||
refreshTokenMutation: JSON.stringify({ | ||
query: "mutation { refreshToken }", | ||
}), | ||
authEndpoint: `${clientApiHostname}/auth/graphql`, | ||
}; | ||
|
||
return <AuthProvider options={authProviderProps}>{children}</AuthProvider>; | ||
``` | ||
|
||
Use the token data | ||
|
||
```tsx | ||
import { useAuth } from '@labdigital/federated-token-react'; | ||
|
||
const { loading, isAuthenticated, values } = useAuth(); | ||
|
||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
return ( | ||
<div>User is authenticated {isAuthenticated}</div> | ||
<div>Values: {values}</div> | ||
) | ||
``` |