# Login with SPA and obtain info with Php

**URL:** <https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232>\
**Category:** Get Help\
**Tags:** auth0-spa-js, sdks-quickstarts\
**Created:** [January 29, 2023, 6:21pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232 "2023-01-29T18:21:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![isimental](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/isimental/32/42852_2.png) [@isimental](https://community.auth0.com/u/isimental)\
**Post date:** [January 29, 2023, 6:21pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/1 "2023-01-29T18:21:53Z")

</div>

I have a Php site and I am using the SPA example with the Universal Login. All works fine. I can login with email and password or with any configured social network

When user login, I got a code and state via GET. My question is this:

How can I use that code/state in Php so I can obtain user info, update info, or something ?

I’m able to do that with the javascript part, but I want it with Php

Currently, when I got the code/state, I use this code [GitHub - RiskioFr/oauth2-auth0: Auth0 provider for the OAuth 2.0 Client](https://github.com/RiskioFr/oauth2-auth0) but it fails with a invalid\_grant [error\_description] =\> Invalid authorization code

I’m using this code because the server doesn’t fit the oficial Php code requirements

I have read [Auth0 PHP API SDK Quickstart](https://auth0.com/docs/quickstart/backend/php?_gl=1*1hpkzfr*rollup_ga*OTg4MzYzNTMyLjE2NzQwNzk3Njg.*rollup_ga_F1G3E656YZ*MTY3NTAxNDA3Mi4xNS4xLjE2NzUwMTc1NjIuMTkuMC4w&_ga=2.11213878.300354719.1674881948-988363532.1674079768#configure-jwt-validation) and also [GitHub - auth0/auth0-spa-js: Auth0 authentication for Single Page Applications (SPA) with PKCE](https://github.com/auth0/auth0-spa-js) but can’t obtain that token, just code/state

Update:

Following the step 2 in [Call Your API Using the Authorization Code Flow (auth0.com)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow) I got an error: code\_verifier is required

The same following this code [Authentication API Explorer (auth0.com)](https://auth0.com/docs/api/authentication?http#get-token)

Looks like it’s having something to do with [Authorization Code Flow with Proof Key for Code Exchange (PKCE) (auth0.com)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce) but don’t know how to remove that and make it work

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 31, 2023, 3:38pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/3 "2023-01-31T15:38:04Z")

</div>

Hi @isimental,

Welcome to the Auth0 Community!

The _auth code_ is not meant to be shared between your frontend and backend. That is the purpose of the Access Token. Is there a reason why you aren’t using the AT?

---

<div class="post-metadata">

**Author:** ![isimental](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/isimental/32/42852_2.png) [@isimental](https://community.auth0.com/u/isimental)\
**Post date:** [January 31, 2023, 4:27pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/4 "2023-01-31T16:27:07Z")

</div>

Thanks for your reply

After my last upodate, I search and test a lot of things. As I said, I can’t use the SDK because the server doesn’t fit the requirements, so I was thinking in using the API directly

Changed the login link to https://{DOMAIN}/authorize and then I send the retrieved code to https://{DOMAIN}/oauth/token and now I got the access\_token

I have strugglin with composer, SDK, grant types, PKCE, code verifier, audience, managment API, machine to machine, native web or PSA, and stuff I don’t remember anymore. Dunno why is there so many options/ways

The next step is get the user info… seems the grant\_type must be client\_credentials instead of authorization\_code, but then I got an error with audience. Will try in a few hours

Hope there is a sample/doc that uses API directly. I’m working with Php and Curl

Btw, is there a way to combine users? Currently Auth0 creates a different user when sigin with different social networks but the email is in fact the same

Another one… Twitter does provides email - [GET account/verify\_credentials | Docs | Twitter Developer Platform](https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials)

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 31, 2023, 8:05pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/5 "2023-01-31T20:05:45Z")

</div>

Let’s take a step back.

Are you building a SPA? Typically, a PHP app would be more like a _Regular Web App._

Why can’t you use an SDK? Most of the things you are struggling with here are **not Auth0 concepts** , but rather, they are parts of the OAuth2.0/OIDC protocol, which Auth0 didn’t create.

One of the benefits of Auth0 is that you _don’t have to have a expert understanding of the protocols to implement them._ By not using an SDK, you are mostly negating that benefit.

Also, take a look at [User Account Linking](https://auth0.com/docs/manage-users/user-accounts/user-account-linking).

---

<div class="post-metadata">

**Author:** ![isimental](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/isimental/32/42852_2.png) [@isimental](https://community.auth0.com/u/isimental)\
**Post date:** [January 31, 2023, 9:38pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/6 "2023-01-31T21:38:27Z")

</div>

Yep, is a Regular Web App, but when I was looking for examples, all point to the Php SDK, So I tried the SPA and then works, the first step

Can’t use the SDK because the server is a little old and has many projects, so can’t upgrade Php to version 8

I don’t mind using Rest/API, I have used Facebook, Messenger. Whatsapp, Slack, Twittter, Paypal, Apple, Amazon, even Oauth directly a few years ago, and many others. This is one of the first time I have, let’s say, issues with some technology

In fact, I can login/signin users via Social media on my own, but my boss says must use Auth0, mainly to avoid wasting time on updating code everytime a social network change something. Of course, we plan to pay one of the plans

Sorry if I sound rude, I can’t express myself properly because english is not my native language 😅

I just looking for help, don’t want somebody to do the work for me. Just a guide on where or what to search

- Want to login/register - I’m able to do that with /autorize
- I can obtain the access\_token using the /oauth/token
- Need to obtain name, email, type of login (auth, social)
- Later, will deal on how to refresh the token and other stuff

I’m thinking on this: If I’m able to login/register a user and got a code/state, why can’t just simply call some Auth0 API to obtain the info? Why do I need to deal with Oauth?

Thanks for any help 👍🏻

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [February 1, 2023, 2:31pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/7 "2023-02-01T14:31:15Z")

</div>

> [@isimental](#):
>
> Yep, is a Regular Web App, but when I was looking for examples, all point to the Php SDK, So I tried the SPA and then works, the first step

If you are not using a client side app, I would suggest using this flow: [Authorization Code Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow).

> [@isimental](#):
>
> Can’t use the SDK because the server is a little old and has many projects, so can’t upgrade Php to version 8

Okay, that makes sense.

> [@isimental](#):
>
> Sorry if I sound rude, I can’t express myself properly because english is not my native language 😅

Don’t worry, you don’t sound rude 😄

> [@isimental](#):
>
> Need to obtain name, email, type of login (auth, social)

This info is available in the ID token or via the /userinfo endpoint (in exchange for the access token).

> [@isimental](#):
>
> If I’m able to login/register a user and got a code/state, why can’t just simply call some Auth0 API to obtain the info? Why do I need to deal with Oauth?

The ‘code’ and ‘state’ are parts Oauth2/OIDC code flow.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 28, 2023, 1:22pm UTC](https://community.auth0.com/t/login-with-spa-and-obtain-info-with-php/99232/8 "2023-03-28T13:22:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
