Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BrianHenryIE/60e2976f351f8f1e87c2dd94677c7a37 to your computer and use it in GitHub Desktop.
Save BrianHenryIE/60e2976f351f8f1e87c2dd94677c7a37 to your computer and use it in GitHub Desktop.
diff --git a/includes/callback.php b/includes/callback.php
index 81ca282..abe992f 100644
--- a/includes/callback.php
+++ b/includes/callback.php
@@ -74,13 +74,20 @@ if ( isset( $_GET['code'] ) && ! empty( $_GET['code'] ) ) {
$user_info = json_decode( $response['body'] );
$user_id = username_exists( $user_info->user_login );
if ( ! $user_id && email_exists( $user_info->user_email ) == false ) {
-
+
+ $new_user_permitted = true;
+ $new_user_permitted = apply_filters( 'oauth-single-sign-on-permit-user', $new_user_permitted, $user_info );
+ if ( ! $new_user_permitted )
+ wp_die( "Account cannot be created for this user" );
+
// Does not have an account... Register and then log the user in
$random_password = wp_generate_password( $length = 12, $include_standard_special_chars = false );
$user_id = wp_create_user( $user_info->user_login, $random_password, $user_info->user_email );
wp_clear_auth_cookie();
wp_set_current_user( $user_id );
wp_set_auth_cookie( $user_id );
+
+ do_action( 'oauth-single-sign-on-new-user', $user_info, $user_id );
if ( is_user_logged_in() ) {
wp_redirect( $user_redirect );
@@ -102,6 +109,8 @@ if ( isset( $_GET['code'] ) && ! empty( $_GET['code'] ) ) {
wp_set_current_user( $user->ID );
wp_set_auth_cookie( $user->ID );
+ do_action( 'oauth-single-sign-on', $user );
+
if ( is_user_logged_in() ) {
wp_redirect( $user_redirect );
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment