B4J Tutorial [Web][SithasoDaisy] PocketBase - Configuring & Adding Google Authentication to your Apps

Hi Fam

Step 1

1. Create client id and client secret. On the Google API, select "Credentials" > Create Credentials > OAuth Client ID

Follow these instructions here from the google api console.


You will use the Client ID & Client Secret in the PocketBase Admin Screen > Settings > Auth Providers

Step 2

OAuth Consent Screen. Update your app settings for the consent screen. I didnt use a logo for my app. For testing purposes, I have used "http://127.0.0.1:8010/api/oauth2-redirect" for the redirect url. My app is running on port 8010.

Step 3

In your PocketBase Admin screen, select settings on

1711541271050.png


The Auth Providers

1711541299995.png


Select the Google gear and update the Client ID and Client Secret with the content you got from google and save.

In your app call,

B4X:
Dim userData As Map = banano.Await(pb.USER_AUTH_WITH_GOOGLE)

This will show a google web prompt to authenticate your app.

Have fun!
 

Mashiane

Expert
Licensed User
Longtime User
Example Project:

Clicking Google Auth, will activate the google auth prompt and ask one to confirm the account. After which the details on the screen will be updated.

1711545589390.png


PS: Sign Out - will not expire the token before time.

Reproduction:

1. Download PocketBase
2. Unzip PocketBase.zip file to C:\sdgoogleauth
3. Create a folder named C:\sdgoogleauth\pb_bublic
4. Unzip the googleauth.zip contents into the root of c:\sdgoogleauth.
5. Double click the run_server_8010.bat file
6. Run your application in B4J and refresh your browser tab
 

Attachments

  • SDAuthWithGoogle.zip
    36.2 KB · Views: 21
  • sdgoogleauth.zip
    718 bytes · Views: 20
Top