Skip to content

Commit

Permalink
Merge pull request #270 from auth0/add-passwordless-endpoints
Browse files Browse the repository at this point in the history
Add passwordless endpoints
  • Loading branch information
lbalmaceda authored Jan 29, 2020
2 parents eeea624 + a7c7cb7 commit b061c42
Show file tree
Hide file tree
Showing 4 changed files with 580 additions and 112 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,57 @@ auth0.auth
.catch(console.error);
```

#### Login with Passwordless

Passwordless is a two-step authentication flow that makes use of this type of connection. The **Passwordless OTP** grant is required to be enabled in your Auth0 application beforehand. 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 code to be sent to the user's email or phone number. For email scenarios only, a link can be sent in place of the code.

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

or

```js
auth0.auth
.passwordlessWithSMS({
phoneNumber: '+5491159991000',
})
.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
150 changes: 150 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,156 @@ Array [
]
`;

exports[`auth passwordless flow with SMS connection should begin with code 1`] = `
Array [
"https://samples.auth0.com/passwordless/start",
Object {
"body": "{\\"phone_number\\":\\"+5491159991000\\",\\"send\\":\\"code\\",\\"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 begin with optional parameters 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 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 parameters 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 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 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 begin with optional parameters 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 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 parameters 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

0 comments on commit b061c42

Please sign in to comment.