# Login Dialog



Calling `FB.login()` prompts the user to authenticate your app using the [Login Dialog](https://developers.facebook.com/documentation/facebook-login/web).

#### Avoid Popup Blocking

Calling `FB.login()` results in the JS SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.

#### Status `unknown` in Canvas

On Canvas, if the user is `unknown` (that is, when the login `status == 'unknown'`), do not use the JS SDK to sign in the user, instead do a full redirect of the page to the login dialog so that we get a consistent state.

## Example

```
FB.login(function(response) {
    if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
    } else {
     console.log('User cancelled login or did not fully authorize.');
    }
});
```

## Permissions {#permissions}

By default, calling `FB.login()` will attempt to authenticate the user with only the basic permissions. If you want one or more [additional permissions](https://developers.facebook.com/docs/reference/api/permissions), call `FB.login()` with an option object, and set the scope parameter with a comma-separated [list of the permissions](https://developers.facebook.com/docs/reference/api/permissions) you wish to request from the user.

```
FB.login(function(response) {
  // handle the response
}, {scope: 'email,user_likes'});
```

Asking for more permissions decreases the number of users who will choose to authenticate your app. As such, you should ask for as few permissions as possible the first time you want a user to authenticate your app.

By setting the `return_scopes` option to `true` in the option object when calling `FB.login()`, you will receive a list of the granted permissions in the `grantedScopes` field on the `authResponse` object.

```
FB.login(function(response) {
    // handle the response
}, {
    scope: 'email',
    return_scopes: true
});
```

If you need to collect more permissions from users who have already authenticated with your app, call `FB.login()` again with the permissions you want the user to grant. In the Login dialog, the user will only ever be asked for permissions they have not already granted.

## Parameters {#params}

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `cb` | function | no | The callback function. |
| `opts` | object | yes | Options to modify login behavior.  See below for properties you can set on the object. |

### Options {#options}

| Name | Type | Description |
| --- | --- | --- |
| `auth_type` | string | Optional key, supports 3 values: `rerequest`, `reauthenticate`, `reauthorize`.  Use `rerequest` when re-requesting a [declined permission](https://developers.facebook.com/documentation/facebook-login/web/permissions#re-asking-declined-permissions). |
| `scope` | string | Comma separated list of [extended permissions](https://developers.facebook.com/docs/reference/login/extended-permissions) |
| `return_scopes` | boolean | When true, the granted scopes will be returned in a comma-separated list in the `grantedScopes` field of the [`authResponse`](https://developers.facebook.com/documentation/javascript/reference/FB.getLoginStatus) |
| `enable_profile_selector` | boolean | When true, prompt the user to grant permission for one or more Pages |
| `profile_selector_ids` | string | Comma separated list of IDs to display in the profile selector |