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
* Clarifying documentation of custom authentication.
Documentation on custom authentication was extremely unclear. Tried to clarify a few aspects. That id is required in the authData object. Also what is client-side vs backend code. Very open to feedback and improvements!
* Update users.md
* Apply suggestions from code review
Co-authored-by: Diamond Lewis <[email protected]>
Co-authored-by: Tom Fox <[email protected]>
Copy file name to clipboardExpand all lines: _includes/js/users.md
+18-9
Original file line number
Diff line number
Diff line change
@@ -389,7 +389,7 @@ Our library manages the `FB` object for you. The `FB` singleton is synchronized
389
389
390
390
Parse allows you to link your users with [3rd party authentication]({{ site.baseUrl }}/parse-server/guide/#oauth-and-3rd-party-authentication), enabling your users to sign up or log into your application using their existing identities. This is accomplished through [`linkWith`](https://parseplatform.org/Parse-SDK-JS/api/2.9.0/Parse.User.html#linkWith) method by providing authentication data for the service you wish to link to a user in the `authData` field. Once your user is associated with a service, the `authData` for the service will be stored with the user and is retrievable by logging in.
391
391
392
-
`authData` is a JSON object with keys for each linked service containing the data below.
392
+
`authData` is a JSON object with keys for each linked service containing the data below. The `authData` object is required to at least have a key named `id`, which is used to identify the user on subsequent login attempts with linked account data.
393
393
394
394
> `_linkWith` has been deprecated since version 2.9.0, see [_linkWith](https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#_linkWith)
395
395
@@ -399,7 +399,7 @@ Signing a user up with a linked service and logging them in with that service us
399
399
400
400
```javascript
401
401
constmyAuthData= {
402
-
id:'12345678'
402
+
id:'12345678'// Required field. Used to uniquely identify the linked account.
@@ -450,7 +450,7 @@ To create a link to an un-authenticated user (for example in cloud code), option
450
450
451
451
```javascript
452
452
constmyAuthData= {
453
-
id: xzx5tt123,
453
+
id: xzx5tt123,// The id key is required in the authData-object. Otherwise Parse Server will throw the Error 252 'This authentication method is unsupported'.
Parse Server supports many [3rd Party Authenications]({{ site.baseUrl }}/parse-server/guide/#oauth-and-3rd-party-authentication).
476
-
It is possible to `linkWith` any 3rd Party Authentication by creating a custom authentication module.
476
+
It is possible to `linkWith` any 3rd Party Authentication by creating a custom authentication module. A custom authentication module normally consists of a client-side AuthProvider object and a back-end AuthAdapter. The client-side object should implement the [AuthProvider interface](https://github.com/parse-community/Parse-SDK-JS/blob/master/src/interfaces/AuthProvider.js). The backend AuthAdapter should implement the the functions `validateAuthData` and `validateAppId`, check out this [AuthAdapter example](https://github.com/parse-community/parse-server/blob/master/src/Adapters/Auth/AuthAdapter.js).
477
+
When calling the `linkWith` function **without** an `authData` object the client side authenticate-method from the provider object will be called. In the other case the `authData` object will be sent directly to Parse Server for authentication using the backend module.
477
478
478
-
[Read more about Auth Provider Documentation](https://github.com/parse-community/Parse-SDK-JS/blob/master/src/interfaces/AuthProvider.js)
479
+
Note: The following is a minimal example implementing AuthProvider client-side and AuthAdapter on the backend.
479
480
480
-
Note: This is an example, you can handle your own authentication (if you don't have authData), restoreAuthentication and deauthenticate methods.
481
-
482
-
A minimal `CustomAuth.js` module:
481
+
A minimal `CustomAuth.js` module in the backend:
483
482
```javascript
483
+
// Don't require or import parse-server in this module.
484
+
// See this issue: https://github.com/parse-community/parse-server/issues/6467
484
485
functionvalidateAuthData(authData, options) {
485
486
returnPromise.resolve({})
486
487
}
@@ -517,7 +518,15 @@ app.use('/parse', api);
517
518
Use the `CustomAuth`:
518
519
```javascript
519
520
constprovider= {
520
-
authenticate: () =>Promise.resolve(),
521
+
authenticate: (options) => {
522
+
// Some code to get retrieve authData
523
+
// If retrieved valid authData, call success function with the data
0 commit comments