UNPKG

31.2 kBMarkdownView Raw
1[![NPM version][npm-image]][npm-url]
2[![Build status][circleci-image]][circleci-url]
3[![Dependency Status][david-image]][david-url]
4[![License][license-image]][license-url]
5[![Downloads][downloads-image]][downloads-url]
6
7# Lock
8
9[Auth0](https://auth0.com) is an authentication broker that supports both social and enterprise identity providers, including Active Directory, LDAP, Google Apps, and Salesforce.
10
11## Table of Contents
121. [Install](#install)
132. [Cross Origin Authentication](#cross-origin-authentication)
143. [API](#api)
154. [Browser Compatibility](#browser-compatibility)
165. [Issue Reporting](#issue-reporting)
176. [Author](#author)
187. [License](#license)
19
20## Install
21
22From CDN
23
24```html
25<!-- Latest patch release (recommended for production) -->
26<script src="https://cdn.auth0.com/js/lock/11.23.0/lock.min.js"></script>
27```
28
29From [npm](https://npmjs.org)
30
31```sh
32npm install auth0-lock
33```
34
35Then you can import `Auth0Lock` or `Auth0LockPasswordless` like this:
36
37```js
38import Auth0Lock from 'auth0-lock';
39// OR
40import { Auth0Lock } from 'auth0-lock';
41import { Auth0LockPasswordless } from 'auth0-lock';
42```
43
44After installing the `auth0-lock` module, you'll need to bundle it up along with all of its dependencies. See examples for [browserify](examples/bundling/browserify/) and [webpack](examples/bundling/webpack/).
45
46> It is expected that you use the development mode when working on your app, and the production mode when deploying your app to the users.
47> You can find instructions for building your app for production with different module bundlers [here](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build).
48
49If you are targeting mobile audiences, we recommended that you add:
50
51```html
52<meta name="viewport" content="width=device-width, initial-scale=1"/>
53```
54## Cross-Origin Authentication
55
56Lock uses **Cross-Origin Authentication**, make sure you understand the considerations you need to take into account by reading the [Cross-Origin Authentication documentation](https://auth0.com/docs/cross-origin-authentication).
57
58## API
59
60### new Auth0Lock(clientID, domain, options)
61
62Initializes a new instance of `Auth0Lock` configured with your application `clientID` and your account's `domain` at [Auth0](https://manage.auth0.com/). You can find this information in your [application settings](https://manage.auth0.com/#/applications).
63
64- **clientId {String}**: Your application _clientId_ in Auth0.
65- **domain {String}**: Your Auth0 _domain_. Usually _your-account.auth0.com_.
66- **options {Object}**: Allows you to customize the dialog's appearance and behavior. See [below](#customization) for the details.
67
68#### Example
69
70```js
71var clientId = "YOUR_AUTH0_APP_CLIENTID";
72var domain = "YOUR_DOMAIN_AT.auth0.com";
73var lock = new Auth0Lock(clientId, domain);
74var accessToken = null;
75var profile = null;
76
77lock.on("authenticated", function(authResult) {
78 lock.getUserInfo(authResult.accessToken, function(error, profileResult) {
79 if (error) {
80 // Handle error
81 return;
82 }
83
84 accessToken = authResult.accessToken;
85 profile = profileResult;
86
87 // Update DOM
88 });
89});
90```
91
92### new Auth0LockPasswordless(clientID, domain, options)
93
94Initializes a new instance of `Auth0LockPasswordless` configured with your application `clientID` and your account's `domain` at [Auth0](https://manage.auth0.com/). You can find this information in your [application settings](https://manage.auth0.com/#/applications).
95
96- **clientId {String}**: Your application _clientId_ in Auth0.
97- **domain {String}**: Your Auth0 _domain_. Usually _your-account.auth0.com_.
98- **options {Object}**: Allows you to customize the dialog's appearance and behavior. See [below](#customization) for the details.
99
100If both SMS and email passwordless connections are enabled [in the dashboard](https://manage.auth0.com/#/connections/passwordless), Lock will pick email by default. If you want to conditionally pick email or SMS, use the [`allowedConnections`](#ui-options) option, for example: `allowedConnections: ['sms']`.
101
102For more information, read our [passwordless docs](https://auth0.com/docs/connections/passwordless).
103
104#### Example
105
106```js
107var clientId = "YOUR_AUTH0_APP_CLIENTID";
108var domain = "YOUR_DOMAIN_AT.auth0.com";
109var lock = new Auth0LockPasswordless(clientId, domain);
110var accessToken = null;
111var profile = null;
112
113lock.on("authenticated", function(authResult) {
114 lock.getUserInfo(authResult.accessToken, function(error, profileResult) {
115 if (error) {
116 // Handle error
117 return;
118 }
119
120 accessToken = authResult.accessToken;
121 profile = profileResult;
122
123 // Update DOM
124 });
125});
126```
127
128### getUserInfo(accessToken, callback)
129
130Once the user has logged in and you are in possession of an access token, you can obtain the profile with `getUserInfo`.
131
132- **accessToken {String}**: User access token.
133- **callback {Function}**: Will be invoked after the user profile has been retrieved.
134
135#### Example
136
137```js
138lock.getUserInfo(accessToken, function(error, profile) {
139 if (!error) {
140 alert("hello " + profile.name);
141 }
142});
143```
144
145### on(event, callback)
146
147Lock will emit events during its lifecycle.
148
149- `show`: emitted when Lock is shown. Has no arguments.
150- `hide`: emitted when Lock is hidden. Has no arguments.
151- `unrecoverable_error`: emitted when there is an unrecoverable error, for instance when no connection is available. Has the error as the only argument.
152- `authenticated`: emitted after a successful authentication. Has the authentication result as the only argument.
153- `authorization_error`: emitted when authorization fails. Has the error as the only argument.
154- `hash_parsed`: every time a new Auth0Lock object is initialized in redirect mode (the default), it will attempt to parse the hash part of the URL looking for the result of a login attempt. This is a _low-level_ event for advanced use cases and _authenticated_ and _authorization_error_ should be preferred when possible. After that, this event will be emitted with `null` if it couldn't find anything in the hash. It will be emitted with the same argument as the `authenticated` event after a successful login or with the same argument as `authorization_error` if something went wrong. This event won't be emitted in popup mode because there is no need to parse the URL's hash part.
155- `forgot_password ready`: emitted when the "Forgot password" screen is shown.
156- `forgot_password submit`: emitted when the user clicks on the submit button of the "Forgot password" screen.
157- `signin submit`: emitted when the user clicks on the submit button of the "Login" screen.
158- `signup submit`: emitted when the user clicks on the submit button of the "Sign up" screen.
159- `signup success`: emitted when the user successfully signs up.
160- `signup error`: emitted when signup fails. Has the error as an argument.
161- `federated login`: emitted when the user clicks on a social connection button. Has the connection name and the strategy as arguments.
162- `sso login`: emitted when the user clicks on an enterprise SSO connection button. Has the lock ID, connection object, and field name as arguments.
163
164### show(options)
165
166Displays the widget, allowing you to override some options.
167
168- **options {Object}**: Allows you to customize some aspect of the dialog's appearance and behavior. The options allowed in here are a subset of the options allowed in the constructor and will override them: `allowedConnections`, `auth.params`, `allowLogin`, `allowSignUp`, `allowForgotPassword`, `initialScreen`, `rememberLastLogin`, `flashMessage` and `languageDictionary`. See [below](#customization) for the details. Keep in mind that `auth.params` will be fully replaced and not merged.
169
170#### Example
171
172```js
173// without options
174lock.show();
175
176// will override the allowedConnections option passed to the constructor, if any
177lock.show({allowedConnections: ["twitter", "facebook"]})
178
179// will override the entire auth.params object passed to the constructor, if any
180lock.show({auth: {params: {state: 'auth_state'}}})
181```
182
183### resumeAuth(hash, callback)
184
185If you set the [auth.autoParseHash](#authentication-options) option to `false`, you'll need to call this method to complete the authentication flow. This method is useful when you're using a client-side router that uses a `#` to handle URLs (angular2 with `useHash` or react-router with `hashHistory`).
186- **hash {String}**: The hash fragment received from the redirect.
187- **callback {Function}**: Will be invoked after the parse is done. Has an error (if any) as the first argument and the authentication result as the second one. If there is no hash available, both arguments will be `null`.
188
189#### Example
190
191```js
192lock.resumeAuth(hash, function(error, authResult) {
193 if (error) {
194 alert("Could not parse hash");
195 }
196 console.log(authResult.accessToken);
197});
198```
199
200### logout(options)
201
202Logs out the user.
203
204- **options {Object}**: This is optional and follows the same rules as [this](https://auth0.com/docs/libraries/auth0js#logout).
205
206#### Example
207
208```js
209lock.logout({ returnTo: 'https://myapp.com/bye-bye' });
210```
211
212### checkSession(params, callback)
213
214The checkSession method allows you to acquire a new token from Auth0 for a user who is already authenticated against the universal login page for your domain. The method accepts any valid OAuth2 parameters that would normally be sent to authorize. In order to use this method, you have to enable Web Origins for your application. For more information, see [Using checkSession to acquire new tokens](https://auth0.com/docs/libraries/auth0js#using-checksession-to-acquire-new-tokens).
215- **params {Object}**: OAuth2 params object to send to Auth0's servers.
216- **callback {Function}**: Will be invoked after the response from the server is returned. Has an error (if any) as the first argument and the authentication result as the second one.
217
218#### Example
219
220```js
221lock.checkSession({}, function (error, authResult) {
222 if (error || !authResult) {
223 lock.show();
224 } else {
225 // user has an active session, so we can use the accessToken directly.
226 lock.getUserInfo(authResult.accessToken, function (error, profile) {
227 console.log(error, profile);
228 });
229 }
230});
231```
232
233### Customization
234
235The appearance of the widget and the mechanics of authentication can be customized with an `options` object which has one or more of the following properties. Each method that opens the dialog can take an `options` object as its first argument.
236
237#### UI options
238
239- **allowedConnections {Array}**: List of connection that will be available to perform the authentication. It defaults to all enabled connections.
240- **autoclose {Boolean}**: Determines whether or not the Lock will be closed automatically after a successful sign in. If the Lock is not `closable` it won't be closed even if this option is set to `true`. Defaults to `false`.
241- **autofocus {Boolean}**: Determines whether or not the first input on the screen, that is the email or phone number input, should have focus when the Lock is displayed. Defaults to `false` when a `container` option is provided or the Lock is being rendered on a mobile device. Otherwise, it defaults to `true`.
242- **avatar {Object}**: Determines whether or not an avatar and a username should be displayed on the Lock's header once an email or username has been entered and how to obtain it. By default avatars are fetched from [Gravatar](https://gravatar.com/). Supplying `null` will disable the functionality. To fetch avatar from other provider see [below](#avatar-provider).
243- **container {String}**: The `id` of the HTML element where the Lock will be rendered. This makes the Lock appear inline instead of in a modal window.
244- **language {String}**: Specifies the language of the widget. Defaults to `"en"`. Supported languages are:
245 - `de`: German
246 - `en`: English
247 - `es`: Spanish
248 - `it`: Italian
249 - `nb`: Norwegian bokmål
250 - `pt-BR`: Brazilian Portuguese
251 - `ru`: Russian
252 - `zh`: Chinese
253 - `ja`: Japanese
254 - [Check all the available languages](https://github.com/auth0/lock/tree/master/src/i18n)
255- **languageDictionary {Object}**: Allows you to customize every piece of text displayed in the Lock. Defaults to `{}`. See below [Language Dictionary Specification](#language-dictionary-specification) for the details.
256- **closable {Boolean}**: Determines whether or not the Lock can be closed. When a `container` option is provided its value is always `false`, otherwise it defaults to `true`.
257- **popupOptions {Object}**: Allows you to customize the location of the popup in the screen. Any [position and size feature](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Position_and_size_features) allowed by `window.open` is accepted. Defaults to `{}`.
258- **rememberLastLogin {Boolean}**: Determines whether or not to show a screen that allows you to quickly log in with the account you used the last time when the `initialScreen` option is set to `"login"` (the default). Defaults to `true`.
259- **flashMessage {Object}**: Shows an `error` or `success` flash message when Lock is shown.
260 + **type {String}**: The message type, it should be `error` or `success`.
261 + **text {String}**: The text to show.
262- **allowAutocomplete {Boolean}**: Determines whether or not the email or username inputs will allow autocomplete (`<input autocomplete />`). Defaults to `false`.
263- **scrollGlobalMessagesIntoView {Boolean}**: Determines whether or not a globalMessage should be scrolled into the user's viewport. Defaults to `true`.
264- **allowShowPassword {Boolean}**: Determines whether or not add a checkbox to show the password when typing it. Defaults to `false`.
265- **allowPasswordAutocomplete {Boolean}**: Determines whether the password field will allow autocomplete; setting this to `true` is required for password manager support and to avoid many cases of adverse behavior. Defaults to `false`.
266
267
268#### Theming options
269
270Theme options are grouped in the `theme` property of the `options` object.
271
272```js
273var options = {
274 theme: {
275 labeledSubmitButton: false,
276 logo: "https://example.com/assets/logo.png",
277 primaryColor: "green",
278 authButtons: {
279 connectionName: {
280 displayName: "...",
281 primaryColor: "...",
282 foregroundColor: "...",
283 icon: "https://.../logo.png"
284 }
285 }
286 }
287};
288```
289
290- **labeledSubmitButton {Boolean}**: Indicates whether or not the submit button should have a label. Defaults to `true`. When set to `false` an icon will be shown. The labels can be customized through the `languageDictionary`.
291- **logo {String}**: Url for an image that will be placed in the Lock's header. Defaults to Auth0's logo.
292- **primaryColor {String}**: Defines the primary color of the Lock, all colors used in the widget will be calculated from it. This option is useful when providing a custom `logo` to ensure all colors go well together with the logo's color palette. Defaults to `"#ea5323"`.
293- **authButtons {Object}**: Allows the customization of the custom oauth2 login buttons.
294 + **displayName {String}**: The name to show instead of the connection name.
295 + **primaryColor {String}**: The button's background color. Defaults to `"#eb5424"`.
296 + **foregroundColor {String}**: The button's text color. Defaults to `"#FFFFFF"`.
297 + **icon {String}**: The icon's url for the connection. For example:`"https://site.com/logo.png"`.
298
299#### Authentication options
300
301Authentication options are grouped in the `auth` property of the `options` object. The default scope used by Lock is `openid profile email`.
302
303```js
304var options = {
305 auth: {
306 params: {
307 param1: "value1",
308 scope: "openid profile email"
309 },
310 autoParseHash: true,
311 redirect: true,
312 redirectUrl: "some url",
313 responseMode: "form_post",
314 responseType: "token",
315 sso: true,
316 connectionScopes: {
317 connectionName: [ 'scope1', 'scope2' ]
318 }
319 }
320};
321```
322
323- **params {Object}**: Specifies extra parameters that will be sent when starting a login. Defaults to `{}`.
324- **autoParseHash {Boolean}**: When set to `true`, Lock will parse the `window.location.hash` string when instantiated. If set to `false`, you'll have to manually resume authentication using the [resumeAuth](#resumeauthhash-callback) method.
325- **redirect {Boolean}**: When set to `true`, the default, _redirect mode_ will be used. Otherwise, _popup mode_ is chosen. See [below](#popup-mode) for more details.
326- **redirectUrl {String}**: The URL Auth0 will redirect back to after authentication. Defaults to the empty string `""` (no redirect URL).
327- **responseMode {String}**: Should be set to `"form_post"` if you want the code or the token to be transmitted via an HTTP POST request to the `redirectUrl` instead of being included in its query or fragment parts. Otherwise, it should be omitted.
328- **responseType {String}**: Should be set to `"token"` for Single Page Applications, and `"code"` otherwise. Also, `"id_token"` is supported for the first case. Defaults to `"code"` when `redirectUrl` is provided, and to `"token"` otherwise.
329- **sso {Boolean}**: Determines whether Single Sign-On is enabled or not in **Lock**. The Auth0 SSO session will be created regardless of this option if SSO is enabled for your application or tenant.
330- **connectionScopes {Object}**: Allows you to set scopes to be sent to the oauth2/social connection for authentication.
331
332#### Database options
333
334- **additionalSignUpFields {Array}**: Allows you to provide extra input fields during sign up. See [below](#additional-sign-up-fields) more for details. Defaults to `[]`.
335- **allowLogin {Boolean}**: When set to `false` the widget won't display the _login screen_. This is useful if you want to use the widget just for signups (the _login and sign up tabs_ in the _sign up screen_ will be hidden) or to reset passwords (the _back button_ in the _forgot password screen_ will be hidden). In such cases you may also need to specify the `initialScreen`, `allowForgotPassword` and `allowSignUp` options. It defaults to `true`.
336- **allowForgotPassword {Boolean}**: When set to `false` hides the _"Don't remember your password?"_ link in the _login screen_, making the _forgot password screen_ unreachable. Defaults to `true`. Keep in mind that if you are using a database connection with a _custom database_ which doesn't have a _change password script_ the forgot password screen won't be available.
337- **allowSignUp {Boolean}**: When set to `false` hides the _login and sign up tabs_ in the _login screen_, making the _sign up screen_ unreachable. Defaults to `true`. Keep in mind that if the database connection has sign ups _disabled_ or you are using a _custom database_ which doesn't have a _create script_, then the sign up screen won't be available.
338- **defaultDatabaseConnection {String}**: Specifies the database connection that will be used when there is more than one available.
339- **initialScreen {String}**: Name of the screen that will be shown when the widget is opened. Valid values are `"login"`, `"signUp"`, and `"forgotPassword"`. If this option is left unspecified, the widget will pick the first screen that is available from the previous list. If you set `initialScreen` to `"forgotPassword"` we recommend that you set `allowLogin` to `"false"`, otherwise a back button will be shown in the forgot password screen and it might not be clear to the user where that back button will take them.
340- **loginAfterSignUp {Boolean}**: Determines whether or not the user will be automatically signed in after a successful sign up. Defaults to `true`.
341- **forgotPasswordLink {String}**: URL for a page that allows the user to reset her password. When set to a non-empty string, the user will be linked to the provided URL when clicking the _"Don't remember your password?"_ link in the _login screen_.
342- **showTerms {Boolean}**: When set to `true` displays the `languageDictionary.signUpTerms` string. Defaults to `true`.
343- **mustAcceptTerms {Boolean}**: When set to `true` displays a checkbox input along with the terms and conditions that must be checked before signing up. The terms and conditions can be specified via the `languageDictionary` option, see the example below. Defaults to `false`.
344- **prefill {Object}**: Allows you to set the initial value for the _email_ and/or _username_ inputs, e.g. `{prefill: {email: "someone@auth0.com", username: "someone"}}`. When omitted no initial value will be provided.
345- **signUpLink {String}**: URL for a page that allows the user to sign up. When set to a non-empty string, the user will be linked to the provided URL when clicking the _sign up_ tab in the _login screen_.
346- **usernameStyle {String}**: Determines what will be used to identify the user for a Database connection that has the `requires_username` flag set, otherwise it will be ignored. Possible values are `"username"` and `"email"` and by default both `username` and `email` are allowed.
347
348#### Enterprise options
349
350- **defaultEnterpriseConnection {String}**: Specifies the enterprise connection which allows you to log in using a username and a password that will be used when there is more than one available or there is a database connection. If a `defaultDatabaseConnection` is provided the database connection will be used and this option will be ignored.
351
352#### Example
353
354```js
355var options = {
356 container: "myContainer",
357 closable: false,
358 languageDictionary: {
359 signUpTerms: "I agree to the <a href='/terms' target='_new'>terms of service</a> and <a href='/privacy' target='_new'>privacy policy</a>.",
360 title: "My Company",
361 },
362 autofocus: false
363};
364```
365
366#### Passwordless options
367
368- **passwordlessMethod {String}**: When using `Auth0LockPasswordless` with an email connection, you can use this option to pick between sending a [code](https://auth0.com/docs/connections/passwordless/spa-email-code) or a [magic link](https://auth0.com/docs/connections/passwordless/spa-email-link) to authenticate the user. Available values for email connections are `code` and `link`. Defaults to `code`. SMS passwordless connections will always use `code`.
369
370#### Other options
371
372- **configurationBaseUrl {String}**: Overrides application settings base URL. By default it uses Auth0's CDN URL when the `domain` has the format `*.auth0.com`. Otherwise, it uses the provided `domain`.
373- **languageBaseUrl {String}**: Overrides the language source URL for Auth0's provided translations. By default it uses to Auth0's CDN URL `https://cdn.auth0.com`.
374- **hashCleanup {Boolean}**: When enabled, it will remove the hash part of the callback URL after the user authentication. Defaults to `true`.
375- **connectionResolver {Function}**: When in use, provides an extensibility point to make it possible to choose which connection to use based on the username information. Has `username`, `context`, and `callback` as parameters. The callback expects an object like: `{type: 'database', name: 'connection name'}`. **This only works for database connections.** Keep in mind that this resolver will run in the form's `onSubmit` event, so keep it simple and fast. **This is a beta feature. If you find a bug, please open a GitHub [issue](https://github.com/auth0/lock/issues/new).**
376
377```js
378var options = {
379 connectionResolver: function (username, context, cb) {
380 var domain = username.includes('@') && username.split('@')[1];
381 if (domain) {
382 // If the username is test@auth0.com, the connection used will be the `auth0.com` connection.
383 // Make sure you have a database connection with the name `auth0.com`.
384 cb({ type: 'database', name: domain });
385 } else {
386 // Use the default approach to figure it out the connection
387 cb(null);
388 }
389 }
390}
391```
392
393#### Language Dictionary Specification
394
395A language dictionary is an object that allows you to customize every piece of text the Lock needs to display. For instance, the following code will change the title displayed in the header and the placeholder for the email field.
396
397```js
398var options = {
399 languageDictionary: {
400 emailInputPlaceholder: "Please enter your email",
401 title: "My Company"
402 },
403};
404```
405
406#### Additional sign up fields
407
408Extra input fields can be added to the sign up screen with the `additionalSignUpFields` option. Every input must have a `name` and a `placeholder`, and an `icon` URL can also be provided. Also, the initial value can be provided with the `prefill` option, which can be a **string** with the value or a **function** that obtains it. Other options depend on the type of the field, which is defined via the `type` option and defaults to `"text"`.
409
410Additional sign up fields are rendered below the default fields in the order they are provided.
411
412##### Text field
413
414A `validator` function can also be provided.
415
416```js
417var options = {
418 additionalSignUpFields: [{
419 name: "address",
420 placeholder: "enter your address",
421 // The following properties are optional
422 ariaLabel: "Address",
423 icon: "https://example.com/assests/address_icon.png",
424 prefill: "street 123",
425 validator: function(address) {
426 return {
427 valid: address.length >= 10,
428 hint: "Must have 10 or more chars" // optional
429 };
430 }
431 }]
432};
433```
434
435If you don't provide a `validator` function a default validator is applied, which requires the text field to contain some value (be non-empty). You can make a field optional by using a validator that always return `true`:
436
437```js
438var options = {
439 additionalSignUpFields: [{
440 name: "address",
441 placeholder: "enter your address (optional)",
442 validator: function() {return true;}
443 }]
444};
445```
446
447If you want to save the value of the attribute in the root of your profile, use `storage: 'root'`. Only a subset of values can be stored this way. The list of attributes that can be added to your root profile is [here](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id). By default, every additional sign up field is stored inside the `user_metadata` object.
448
449```js
450var options = {
451 additionalSignUpFields: [{
452 name: "name",
453 storage: "root"
454 }]
455};
456```
457
458##### Select field
459
460To specify a select field `type: "select"` needs to be provided along with the `options` property.
461
462```js
463var options = {
464 additionalSignUpFields: [{
465 type: "select",
466 name: "location",
467 placeholder: "choose your location",
468 options: [
469 {value: "us", label: "United States"},
470 {value: "fr", label: "France"},
471 {value: "ar", label: "Argentina"}
472 ],
473 // The following properties are optional
474 ariaLabel: "Location",
475 icon: "https://example.com/assests/location_icon.png",
476 prefill: "us"
477 }]
478}
479```
480
481The `options` and the `prefill` value can be provided through a function.
482
483```js
484var options = {
485 additionalSignUpFields: [{
486 type: "select",
487 name: "location",
488 placeholder: "choose your location",
489 options: function(cb) {
490 // obtain options, in case of error you call cb with the error in the
491 // first arg instead of null
492 cb(null, options);
493 },
494 ariaLabel: "Location",
495 icon: "https://example.com/assests/location_icon.png",
496 prefill: function(cb) {
497 // obtain prefill, in case of error you call cb with the error in the
498 // first arg instead of null
499 cb(null, prefill);
500 }
501 }]
502}
503```
504
505##### Checkbox field
506
507To specify a checkbox field use: `type: "checkbox"`
508The `prefill` value can determine the default state of the checkbox and it is required.
509
510```js
511var options = {
512 additionalSignUpFields: [{
513 type: "checkbox",
514 name: "newsletter",
515 prefill: "true",
516 placeholder: "I hereby agree that I want to receive marketing emails from your company",
517 // placeholderHTML - is an optional field and overrides the value of placeholder
518 placeholderHTML: "<b>I hereby agree that I want to receive marketing emails from your company</b>",
519 // ariaLabel - is an optional field
520 ariaLabel: "Activate Newsletter"
521 }]
522}
523```
524
525##### Hidden field
526
527To specify a hidden field use: `type: "hidden"`. Both the `value` and `name` properties are required.
528
529```js
530var options = {
531 additionalSignUpFields: [{
532 type: "hidden",
533 name: "signup_code",
534 value: "foobar123"
535 }]
536}
537```
538
539#### Avatar provider
540
541Lock can show avatars fetched from anywhere. A custom avatar provider can be specified with the `avatar` option by passing an object with the keys `url` and `displayName`. Both properties are functions that take an email and a callback function.
542
543```js
544var options = {
545 avatar: {
546 url: function(email, cb) {
547 // obtain URL for email, in case of error you call cb with the error in
548 // the first arg instead of null
549 cb(null, url);
550 },
551 displayName: function(email, cb) {
552 // obtain displayName for email, in case of error you call cb with the
553 // error in the first arg instead of null
554 cb(null, displayName);
555 }
556 }
557};
558```
559
560### Popup mode
561
562A popup window can be displayed instead of redirecting the user to a social provider website. While this has the advantage of preserving page state, it has some issues. Often times users have popup blockers that prevent the login page from even displaying. There are also known issues with mobile browsers. For example, in recent versions of Chrome on iOS, the login popup does not [close properly](https://github.com/auth0/lock/issues/71) after login. For these reasons, we encourage developers to avoid this mode, even with Single Page Apps.
563
564If you decide to use popup mode you can activate it by passing the option `auth: {redirect: false}` when constructing `Auth0Lock`.
565
566```js
567var clientId = "YOUR_AUTH0_APP_CLIENTID";
568var domain = "YOUR_DOMAIN_AT.auth0.com";
569var options = {
570 auth: {
571 redirect: false
572 }
573};
574
575var lock = new Auth0Lock(clientId, domain, options);
576lock.show();
577```
578
579More information can be found in [Auth0's documentation](https://auth0.com/docs/libraries/lock/v11/authentication-modes#popup-mode).
580
581## Browser Compatibility
582
583We ensure browser compatibility in Chrome, Safari, Firefox and IE >= 10. We currently use [zuul](https://github.com/defunctzombie/zuul) along with [Saucelabs](https://saucelabs.com) to run integration tests on each push.
584
585## Issue Reporting
586
587If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
588
589## Author
590
591[Auth0](https://auth0.com)
592
593## License
594
595This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
596
597
598[circleci-image]: https://img.shields.io/circleci/project/github/auth0/lock.svg?style=flat-square
599[circleci-url]: https://circleci.com/gh/auth0/lock/tree/master
600[npm-image]: https://img.shields.io/npm/v/auth0-lock.svg?style=flat-square
601[npm-url]: https://npmjs.org/package/auth0-lock
602[license-image]: https://img.shields.io/npm/l/auth0-lock.svg?style=flat-square
603[license-url]: #license
604[downloads-image]: https://img.shields.io/npm/dm/auth0-lock.svg?style=flat-square
605[downloads-url]: https://npmjs.org/package/auth0-lock
606[david-image]: https://david-dm.org/auth0/lock/status.svg?style=flat-square
607[david-url]: https://david-dm.org/auth0/lock