Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add passwordless endpoints #270

Merged
merged 8 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,58 @@ auth0.auth
.catch(console.error);
```

#### Login with Passwordless

Passwordless is a two-step authentication flow, and requires the **Passwordless OTP** grant to be enabled in your Auth0 application before-hand. Check [our guide](https://auth0.com/docs/dashboard/guides/applications/update-grant-types) to learn how to enable it.

To start the flow, you request a link or code to be sent to the user's email or phone number:

```js
auth0.auth
.passwordlessWithEmail({
email: 'info@auth0.com',
send: 'link',
})
.then(console.log)
.catch(console.error);
```

or

```js
auth0.auth
.passwordlessWithSMS({
phoneNumber: '+5491159991000',
send: 'code',
})
.then(console.log)
.catch(console.error);
```

Then, in order to complete the authentication, you must send back that received code value along with the email or phone number used:

```js
auth0.auth
.loginWithEmail({
email: 'info@auth0.com',
code: '123456',
})
.then(console.log)
.catch(console.error);
```

or

```js
auth0.auth
.loginWithSMS({
phoneNumber: 'info@auth0.com',
code: '123456',
})
.then(console.log)
.catch(console.error);
```

#### Create user in database connection

```js
Expand Down
120 changes: 120 additions & 0 deletions src/auth/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,126 @@ Array [
]
`;

exports[`auth passwordless flow with SMS connection should begin with code and authParams 1`] = `
Array [
"https://samples.auth0.com/passwordless/start",
Object {
"body": "{\\"phone_number\\":\\"+5491159991000\\",\\"send\\":\\"code\\",\\"authParams\\":{\\"scope\\":\\"openid profile\\"},\\"connection\\":\\"sms\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with SMS connection should begin with link 1`] = `
Array [
"https://samples.auth0.com/passwordless/start",
Object {
"body": "{\\"phone_number\\":\\"+5491159991000\\",\\"send\\":\\"link\\",\\"connection\\":\\"sms\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with SMS connection should continue 1`] = `
Array [
"https://samples.auth0.com/oauth/token",
Object {
"body": "{\\"username\\":\\"+5491159991000\\",\\"otp\\":\\"123456\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\",\\"realm\\":\\"sms\\",\\"grant_type\\":\\"http://auth0.com/oauth/grant-type/passwordless/otp\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with SMS connection should continue with optional params 1`] = `
Array [
"https://samples.auth0.com/oauth/token",
Object {
"body": "{\\"username\\":\\"+5491159991000\\",\\"otp\\":\\"123456\\",\\"audience\\":\\"http://myapi.com\\",\\"scope\\":\\"openid\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\",\\"realm\\":\\"sms\\",\\"grant_type\\":\\"http://auth0.com/oauth/grant-type/passwordless/otp\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with email connection should begin with code and authParams 1`] = `
Array [
"https://samples.auth0.com/passwordless/start",
Object {
"body": "{\\"email\\":\\"info@auth0.com\\",\\"send\\":\\"code\\",\\"authParams\\":{\\"scope\\":\\"openid profile\\"},\\"connection\\":\\"email\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with email connection should begin with link 1`] = `
Array [
"https://samples.auth0.com/passwordless/start",
Object {
"body": "{\\"email\\":\\"info@auth0.com\\",\\"send\\":\\"link\\",\\"connection\\":\\"email\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with email connection should continue 1`] = `
Array [
"https://samples.auth0.com/oauth/token",
Object {
"body": "{\\"username\\":\\"info@auth0.com\\",\\"otp\\":\\"123456\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\",\\"realm\\":\\"email\\",\\"grant_type\\":\\"http://auth0.com/oauth/grant-type/passwordless/otp\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth passwordless flow with email connection should continue with optional params 1`] = `
Array [
"https://samples.auth0.com/oauth/token",
Object {
"body": "{\\"username\\":\\"info@auth0.com\\",\\"otp\\":\\"123456\\",\\"audience\\":\\"http://myapi.com\\",\\"scope\\":\\"openid\\",\\"client_id\\":\\"A_CLIENT_ID_OF_YOUR_ACCOUNT\\",\\"realm\\":\\"email\\",\\"grant_type\\":\\"http://auth0.com/oauth/grant-type/passwordless/otp\\"}",
"headers": Object {
"Accept": "application/json",
"Auth0-Client": "eyJuYW1lIjoicmVhY3QtbmF0aXZlLWF1dGgwIiwidmVyc2lvbiI6IjEuMC4wIn0=",
"Content-Type": "application/json",
},
"method": "POST",
},
]
`;

exports[`auth refresh token should handle oauth error 1`] = `[invalid_request: Invalid grant]`;

exports[`auth refresh token should handle unexpected error 1`] = `[a0.response.invalid: Internal Server Error]`;
Expand Down
Loading