WordPress Single Sign On … aber wie/but how?

Sorry for the language mix but I thought it’s better to have it in both languages :)

Heute habe ich mal keine Lösung, sondern ein Problem. Ich will in WordPress etwas programmieren. Eine Authentifizierung gegenüber einem Altsystem.

Today I have no solution, but a problem. I want to program something in WordPress. An authentication to a legacy system.

Es gibt eine Website (proprietäres System) auf dem sich Besucher registrieren und einloggen. Innerhalb einer Subdomain (wordpress.hauptdomain.com) liegt ein WordPress und der Wunsch ist nun ein Single Sign On bei dem das führende System das Altsystem (hauptdomain.com) ist.

There is a website (proprietary system) where visitors register and log in. Within a subdomain (wordpress.domain.com) is a WordPress and the desire is a single sign on where the leading system is the legacy system (domain.com).

Vom WordPress aus muss nun folgendes passieren:

  • Checken ob der Besucher beim Hauptsystem angemeldet ist.
    Wenn nein, dorthin schicken (erledigt)
  • Wenn der Besucher der WP Site beim Altsystem angemeldet ist, in WP nachsehen, ob es für dessen E-Mail Adresse schon einen WordPress User gibt.
    • Wenn nein, anlegen (erledigt)
    • Wenn ja, im WordPress einloggen (offen)

Looking from the WordPress installation, the following must happen:

  • Check if the visitor is logged in to the main system.
    If not, send to the system (done)
  • If the visitor to the WP site is logged in to the legacy system, check out WP to see if there is already a WordPress user for that e-mail address.
    • If no, create one (done)
    • If yes ja, log into WordPress (to do)

Das Einloggen ist ein mehrschichtiges Problem. Es ist einfach einen “Eingeloggt sein Zustand” auf der entsprechenden Seite zu ermöglichen. Das geht mit diesen beiden Befehlen sogar ohne Passwort (auch interessant :) ).

The log in is a multi-layered problem. It is easy to enable a logged in status on the appropriate page. It works with these two commands even without a password (also interesting :)).

 wp_set_current_user( [user_id], [user_name] );
 wp_set_auth_cookie( [user_id] );

Auf der entsprechenden WordPress Seite sieht es dann auch so aus als wäre man eingeloggt. Die Funktion is_user_logged_in() ergibt TRUE. Im Meta Widget im Frontend erscheint ein Link zur Administration und einer zum Abmelden. Im Kommentarfenster steht “Angemeldet als [user_name], Abmelden?”. Klicke ich auf den Administration Link erscheint das Login Formular (also doch nicht eingeloggt), versuche ich einen Kommentar zu schreiben und zu verschicken, kommt
FEHLER: Bitte fülle die erforderlichen Felder aus (Name, E-Mail-Adresse).” Ich bin also nicht wirklich angemeldet!

On the corresponding WordPress page, it looks like you’re logged in. The function is_user_logged_in () </ em> returns TRUE. In the Meta Widget </ em> in the frontend, a link to Administration </ em> appears and one to Log out </ em>. In the comments window, “Logged in as [user_name], Log out?”. </ em> When I click the Administration </ em> link I’m send to the login form (so I’m not logged in). When I’m trying to write a comment and send it I see an error message
ERROR </ strong>: Please fill in the required fields (name, e-mail address). </ em>” So I am not really logged in!

Scheinbar wird kein Cookie gesetzt (ist auch klar, ist zu spät, muss früher gesetzt werden). Dann habe ich die wp_signon Funktion gefunden.

Apparently, no cookie is set (I know, it’s too late, must be set earlier). Then I found the wp_signon function.

     $creds = array();
     $creds['user_login'] = ... ;
     $creds['user_password'] = ... ;
     $creds['remember'] = true;
     $user = wp_signon( $creds, false );

Die tut aber irgendwie nichts.

But somehow it does not do anything.

Leider kenne ich mich mit WordPress nicht so super aus und brauche da jetzt einfach mal grundsätzliche Hilfe wie da die Dinge zusammenhängen.

Unfortunately, my knowledge in WordPress is not so superduper and now I need to know some basics how things are related.

Wenn du das hier liest und eine Idee hast, wie ich den Login vielleicht hinbekommen könnte oder was der grundsätzliche Weg wäre, so bin ich dir bereits im Voraus für jede Hilfe dankbar (Kommentar, Email, Telefon, Twitter, Facebook, wie es dir am besten passt :) ).

If you are reading this and have an idea about how I might get the login or what the basic path would be, I am grateful for any help in advance (comment, email, phone, twitter, facebook, as it fits you best :)).


Posted

in

, ,

by

Comments

3 responses to “WordPress Single Sign On … aber wie/but how?”

  1. Hagen Graf Avatar

    UPDATE: this article https://premium.wpmudev.org/blog/set-get-delete-cookies/ was interesting for me concerning session handling in WordPress. I didn’t know that it is kind of stateless.
    When I put wp_signon in the functions.php file of the template the cookie is set and the user is logged in.

    But it is a bad idea to change core code from a core template!
    So how do I add code to the functions.php without changing it … ?

  2. Hagen Graf Avatar

    UPDATE III
    To secure functions.php create a child theme!

Leave a Reply

Leave a Reply