diff --git a/fboauth.install b/fboauth.install
index 3043847..af3a238 100644
--- a/fboauth.install
+++ b/fboauth.install
@@ -27,6 +27,8 @@ function fboauth_uninstall() {
   variable_del('fboauth_user_properties');
   variable_del('fboauth_user_connections');
   variable_del('fboauth_user_fields');
+  variable_del('fboauth_autoassign_user_roles');
+  variable_del('fboauth_autoassign_user_roles_remove');
 }

 /**
diff --git a/includes/fboauth.fboauth.inc b/includes/fboauth.fboauth.inc
index cc4b87e..9677f61 100644
--- a/includes/fboauth.fboauth.inc
+++ b/includes/fboauth.fboauth.inc
@@ -84,11 +84,13 @@ function fboauth_action_connect($app_id, $access_token) {
     // If the user is already logged in, associate the two accounts.
     if ($user->uid) {
       fboauth_save($user->uid, $fbuser->id);
+      fboauth_assign_user_roles($user);
       drupal_set_message(t('You\'ve connected your account with Facebook.'));
     }
     // Logins will be denied if the user's account is blocked.
     elseif (fboauth_login_user($account)) {
       fboauth_save($account->uid, $fbuser->id);
+      fboauth_assign_user_roles($user);
       drupal_set_message(t('You\'ve connected your account with Facebook.'));
     }
   }
@@ -96,6 +98,7 @@ function fboauth_action_connect($app_id, $access_token) {
     // If the user is already logged in, associate the two accounts.
     if ($user->uid) {
       fboauth_save($user->uid, $fbuser->id);
+      fboauth_assign_user_roles($user);
       drupal_set_message(t('You\'ve connected your account with Facebook.'));
     }
     // Register a new user only if allowed.
@@ -137,6 +140,10 @@ function fboauth_action_deauth($app_id, $access_token) {
     $fbid = fboauth_fbid_load($user->uid);
     fboauth_save($user->uid, NULL);

+    if (variable_get('fboauth_autoassign_user_roles_remove', TRUE)) {
+      fboauth_remove_user_roles($user);
+    }
+
     // Allow other modules to hook into a deauth event.
     module_invoke_all('fboauth_deauthorize', $user->uid, $fbid);

@@ -202,6 +209,10 @@ function fboauth_create_user($fbuser, $options = array()) {
   module_load_include('inc', 'fboauth', 'includes/fboauth.field');
   fboauth_field_create_user($edit, $fbuser);

+  if ($roles = variable_get('fboauth_autoassign_user_roles', array())) {
+    $edit['roles'] = array_combine($roles, $roles);
+  }
+
   // Allow other modules to manipulate the user information before save.
   foreach (module_implements('fboauth_user_presave') as $module) {
     $function = $module . '_fboauth_user_presave';
@@ -758,6 +769,9 @@ function fboauth_deauthorize() {

     if ($signed_request && $deauth_uid = fboauth_uid_load($signed_request['user_id'])) {
       fboauth_save($deauth_uid, NULL);
+      if (variable_get('fboauth_autoassign_user_roles_remove', TRUE)) {
+        fboauth_remove_user_roles($user);
+      }
       watchdog('fboauth', 'The account for UID @uid has been disconnected from Facebook by the user via Facebook.', array('@uid' => $deauth_uid));

       // Allow other modules to hook into a deauth event.
@@ -805,4 +819,30 @@ function fboauth_parse_signed_request($signed_request, $secret) {
  */
 function fboauth_base64_url_decode($input) {
   return base64_decode(strtr($input, '-_', '+/'));
-}
\ No newline at end of file
+}
+
+/**
+ * Add auto-assign roles to user
+ * @param  object $user User account
+ */
+function fboauth_assign_user_roles(&$user) {
+  if ($roles = variable_get('fboauth_autoassign_user_roles', array())) {
+    $user->roles += array_combine($roles, $roles);
+    user_save($user);
+  }
+}
+
+/**
+ * Remove auto-assign roles from user
+ * @param  object $user User account
+ */
+function fboauth_remove_user_roles(&$user) {
+  if ($roles = variable_get('fboauth_autoassign_user_roles', array())) {
+    foreach ($roles as $rid) {
+      if (!empty($user->roles[$rid])) {
+        unset($user->roles[$rid]);
+      }
+    }
+    user_save($user);
+  }
+}
diff --git a/includes/fboauth.pages.inc b/includes/fboauth.pages.inc
index dc37e44..338f6f7 100644
--- a/includes/fboauth.pages.inc
+++ b/includes/fboauth.pages.inc
@@ -109,6 +109,38 @@ function fboauth_settings_form($form, &$form_state) {
     '#description' => t('Requesting this any of this information is rarely useful during the login process. It is often better to set up dedicated permission requests after the user has created an account for extended access.'),
   );

+  $form['roles'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('User roles'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t('Users can automatically have roles assigned to them when they connect with Facebook.'),
+    '#tree' => FALSE,
+    '#weight' => 30,
+  );
+
+  $roles = user_roles(TRUE);
+  unset($roles[DRUPAL_AUTHENTICATED_RID]);
+  if ($roles) {
+    $form['roles']['fboauth_autoassign_user_roles'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Roles to assign'),
+      '#options' => $roles,
+      '#default_value' => variable_get('fboauth_autoassign_user_roles', array()),
+      '#description' => t('Any roles selected here will automatically be assigned to the user when they connect with Facebook.'),
+    );
+    $form['roles']['fboauth_autoassign_user_roles_remove'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Remove role(s) if deauthorized'),
+      '#default_value' => variable_get('fboauth_autoassign_user_roles_remove', TRUE),
+      '#description' => t('If this is checked, the above role(s) will be removed if the user deauthorizes with Facebook.'),
+    );
+  } else {
+    $form['roles']['fboauth_autoassign_user_roles'] = array(
+      '#markup' => t('There are no custom roles to assign.'),
+    );
+  }
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Save'),
@@ -160,6 +192,11 @@ function fboauth_settings_form_submit($form, &$form_state) {
   variable_set('fboauth_user_properties', array_values(array_filter($form_state['values']['fboauth_user_properties'])));
   variable_set('fboauth_user_connections', array_values(array_filter($form_state['values']['fboauth_user_connections'])));

+  if (!empty($form_state['values']['fboauth_autoassign_user_roles'])) {
+    variable_set('fboauth_autoassign_user_roles', array_values(array_filter($form_state['values']['fboauth_autoassign_user_roles'])));
+    variable_set('fboauth_autoassign_user_roles_remove', $form_state['values']['fboauth_autoassign_user_roles_remove']);
+  }
+
   drupal_set_message(t('The configuration options have been saved.'));
 }

