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
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -319,7 +319,7 @@ Assuming we have registered multiple OAuth providers like this:
319
319
320
320
## Utilities
321
321
322
-
This fastify plugin adds 5 utility decorators to your fastify instance using the same **namespace**:
322
+
This fastify plugin adds 6 utility decorators to your fastify instance using the same **namespace**:
323
323
324
324
-`getAccessTokenFromAuthorizationCodeFlow(request, callback)`: A function that uses the Authorization code flow to fetch an OAuth2 token using the data in the last request of the flow. If the callback is not passed it will return a promise. The callback call or promise resolution returns an [AccessToken](https://github.com/lelylan/simple-oauth2/blob/master/API.md#accesstoken) object, which has an `AccessToken.token` property with the following keys:
-`userinfo(tokenOrTokenSet)`: A function to retrieve userinfo data from Authorization Provider. Both token (as object) or `access_token` string value can be passed.
368
+
369
+
Important note:
370
+
Userinfo will only work when `discovery` option is used and such endpoint is advertised by identity provider.
371
+
372
+
For a statically configured plugin, you need to make a HTTP call yourself.
373
+
374
+
See more on OIDC standard definition for [Userinfo endpoint](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)
375
+
376
+
See more on `userinfo_endpoint` property in [OIDC Discovery Metadata](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata) standard definition.
fastify.googleOAuth2.userinfo(currentAccessToken, { method:'GET', params: { /* add your custom key value pairs here to be appended to request */ } }, (err, userinfo) => {
See [Types](./types/index.d.ts) and usage patterns [in examples](./examples/userinfo.js).
396
+
397
+
Note:
398
+
399
+
We support HTTP `GET` and `POST` requests to userinfo endpoint sending access token using `Bearer` schema in headers.
400
+
You can do this by setting (`via: "header"` parameter), but it's not mandatory since it's a default value.
401
+
402
+
We also support `POST` by sending `access_token` in a request body. You can do this by explicitly providing `via: "body"` parameter.
403
+
366
404
E.g. For `name: 'customOauth2'`, the helpers `getAccessTokenFromAuthorizationCodeFlow` and `getNewAccessTokenUsingRefreshToken` will become accessible like this:
0 commit comments