Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

Adding WSO2 Sign-In to Inventra, My Laravel Inventory App

I built Inventra to manage products, stock, customers, and sales. It already had an email and password login. For this update, I wanted to see how an external identity server could handle sign-in while Inventra kept cont

Adding WSO2 Sign-In to Inventra, My Laravel Inventory App

I built Inventra to manage products, stock, customers, and sales. It already had an email and password login. For this update, I wanted to see how an external identity server could handle sign-in while Inventra kept control of who could access the app.

I added a Sign in with WSO2 button using WSO2 Identity Server 7.3.0 and OpenID Connect. I tested it on Windows with Laragon and MySQL. The original Inventra login is still available.

Inventra on GitHub Β· Pull request #1

Inventra login page with a Sign in with WSO2 button

Inventra login page with the Sign in with WSO2 option.

How sign-in works

  1. The user clicks Sign in with WSO2. Inventra sends the browser to WSO2 with an authorization request and a PKCE challenge.
  2. After the user signs in, WSO2 returns an authorization code to Inventra’s callback. Inventra checks that the response matches the sign-in request in its session and exchanges the code using the original PKCE verifier.
  3. Inventra verifies the ID token’s signature and claims, including the issuer, audience, expiry, and nonce. It looks up an existing Inventra user by the issuer and the token’s subject (sub). When the link exists, Laravel signs in that user and regenerates the session ID. An account that can sign in to WSO2 still needs to be linked before it can get into Inventra. I used the issuer and subject as the account key so that a matching email alone doesn’t grant access.

Setting it up locally

In WSO2, I registered Inventra as a Traditional Web Application with OpenID Connect. I enabled the authorization code grant, made PKCE mandatory with S256, configured client_secret_basic, and registered this exact callback: http://localhost:8000/auth/wso2/callback. The WSO2 OIDC settings guide explains these options.

In Inventra, I installed the dependencies with composer install and ran php artisan migrate to add the identity fields to the users table. Then I added the WSO2 settings to my local .env. In my setup, the issuer and discovery base had different URLs:

WSO2_ENABLED=true
WSO2_ISSUER=https://localhost:9443/oauth2/token
WSO2_PROVIDER_URL=https://localhost:9443/oauth2/oidcdiscovery
WSO2_CLIENT_ID=your-client-id
WSO2_CLIENT_SECRET=your-client-secret
WSO2_REDIRECT_URI=http://localhost:8000/auth/wso2/callback
WSO2_CA_BUNDLE=C:/WSO2/wso2-local.pem

Copy the issuer from your server’s discovery document and keep the real client secret in your local configuration. The provider URL above is the base the client uses to find /.well-known/openid-configuration.

Two things I had to fix

Certificate trust. Edge showed a certificate warning for the local WSO2 installation. I exported my local WSO2 certificate as PEM and set WSO2_CA_BUNDLE so PHP could verify the WSO2 connection. I kept TLS certificate verification enabled. These localhost settings are for development; a deployment needs its own HTTPS URLs and a trusted certificate.

Account linking. My first linking command failed because the email I entered didn’t exist in Inventra. The command takes the email of an existing Inventra account and the exact subject of the WSO2 user. With the default WSO2 subject configuration, that subject was the WSO2 User ID.

php artisan config:clear
php artisan wso2:link-user "[email protected]" "your-wso2-user-id"
php artisan serve --host=localhost --port=8000

What I verified

I opened http://localhost:8000/login, clicked Sign in with WSO2, and signed in as my linked WSO2 test user. WSO2 sent me back to Inventra and the dashboard opened.

Inventra dashboard showing recent sales and low stock products

Inventra dashboard after signing in with WSO2 Identity Server.

The repository also includes feature tests for the linked login, unlinked users, invalid callback state, and token validation. Those tests use a simulated provider; the browser test above used my running WSO2 server.

This project helped me see the distinction between proving someone’s identity and deciding what that person can access. WSO2 handles the first part. Inventra handles the second through explicit account links. One follow-up I’d like to work on is coordinated logout: right now, logging out of Inventra ends its session, and the WSO2 session can still be active.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.