I came upon a little problem during work today. I'm developing an angular frontend for a Drupal backend and want to redirect certain users from the angular site to the Drupal site.

I log in as follows:

public logToDrupal(username: string, password: string): Promise<object> {
    return this.http.post(`${this.globals.env.login}?_format=json`, {
      'name': username,
      'pass': password
    })
      .toPromise();
  }

This returns a Status code: 200 OK and the following JSON:

{
   "current_user":{
      "uid":"1",
      "roles":[
         "authenticated",
         "administrator"
      ],
      "name":"admin"
   },
   "csrf_token":"sometoken",
   "logout_token":"sometoken"
}

I then redirect the user like so:

this.users.logToDrupal(this.username, this.password)
                .then(() => {
                  this.router.navigate(['/externalRedirect', { externalUrl: 'mydrupalbackend.my/admin' }])
                    .catch((err) => {
                      console.log(err);
                    });
                });

And I stumble upon an Access denied: You are not authorized to access this page. page.

After some hours googling I'm still not sure about how to procede. I think this has something to do with setting the session, because Drupal checks for a session, but I don't know how to do this from the frontend. I've tried several things involving the CSRF token to no avail.

Any insight would be much appreciated. Thanks!

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.