Skip to content

Commit

Permalink
docs: Update to GraphQL API Documentation (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcleanandfresh committed Dec 20, 2021
1 parent 4f5b38e commit 0a40221
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-pugs-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@accounts/graphql-api': patch
---

Added additional examples for how to authenticate with @accounts/graphql-api
77 changes: 77 additions & 0 deletions packages/graphql-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,80 @@ input CreateUserProfileInput {
```

The user will be saved in the db with the profile key set.

## Example: Authenticate with a Service

```graphql
mutation Authenticate {
authenticate(serviceName: "password", params: { password: "<pw>", user: { email: "<email>" } })
}
```

1. `serviceName` - corresponds to the package you are using to authenticate (e.g. oauth, password, twitter, instagram, two factor, token, etc).
2. `params` - These will be different depending on the service you are using.

- Twitter/Instagram

```graphql
mutation Authenticate {
authenticate(
serviceName: "twitter"
params: { access_token: "<access-token>", access_token_secret: "<access-token-secret>" }
)
}
```

- OAuth

```graphql
mutation Authenticate {
authenticate(serviceName: "oauth", params: { provider: "<your-provider>" })
}
```

- Password: Below the `user` contains `email` but can contain one or more of `id`, `email` or `username` too.

```graphql
mutation Authenticate {
authenticate(serviceName: "password", params: { password: "<pw>", user: { email: "<email>" } })
}
```

- Two Factor

```graphql
mutation Authenticate {
authenticate(serviceName: "two-factor", params: { code: "<two-factor-code>" })
}
```

- Token

```graphql
mutation Authenticate {
authenticate(serviceName: "token", params: { token: "<token>" })
}
```

### Verify Authentication

The way to check if a user has been successfully authenticated is identical, with the exception that `verifyAuthentication` returns a `boolean` instead of a `LoginResult`:

```graphql
mutation Verify {
verifyAuthentication(
serviceName: "password"
params: { password: "<pw>", user: { email: "<email>" } }
)
}
```

This will return a result similar to this, if your user has been successfully authenticated:

```json
{
"data": {
"verifyAuthentication": true
}
}
```
79 changes: 79 additions & 0 deletions website/docs/transports/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,85 @@ type Student implements User {
}
```

## Examples

### Authenticate with a Service

```graphql
mutation Authenticate {
authenticate(serviceName: "password", params: { password: "<pw>", user: { email: "<email>" } })
}
```

1. `serviceName` - corresponds to the package you are using to authenticate (e.g. oauth, password, twitter, instagram, two factor, token, etc).
2. `params` - These will be different depending on the service you are using.

- Twitter/Instagram

```graphql
mutation Authenticate {
authenticate(
serviceName: "twitter"
params: { access_token: "<access-token>", access_token_secret: "<access-token-secret>" }
)
}
```

- OAuth

```graphql
mutation Authenticate {
authenticate(serviceName: "oauth", params: { provider: "<your-provider>" })
}
```

- Password: Below the `user` contains `email` but can contain one or more of `id`, `email` or `username` too.

```graphql
mutation Authenticate {
authenticate(serviceName: "password", params: { password: "<pw>", user: { email: "<email>" } })
}
```

- Two Factor

```graphql
mutation Authenticate {
authenticate(serviceName: "two-factor", params: { code: "<two-factor-code>" })
}
```

- Token

```graphql
mutation Authenticate {
authenticate(serviceName: "token", params: { token: "<token>" })
}
```

#### Verify Authentication

The way to check if a user has been successfully authenticated is identical, with the exception that `verifyAuthentication` returns a `boolean` instead of a `LoginResult`:

```graphql
mutation Verify {
verifyAuthentication(
serviceName: "password"
params: { password: "<pw>", user: { email: "<email>" } }
)
}
```

This will return a result similar to this, if your user has been successfully authenticated:

```json
{
"data": {
"verifyAuthentication": true
}
}
```

# GraphQL Client

_Client side graphql transport for accounts suite_
Expand Down

0 comments on commit 0a40221

Please sign in to comment.