<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7" -->

---
title: OAuth2 and JWT Logins for MySQL | daily.dev
description: VillageSQL Server's new vsql-oauth2 extension lets MySQL accounts authenticate using OAuth2/OpenID Connect JWTs instead of passwords, sourcing tokens from an...
canonical: https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: OAuth2 and JWT Logins for MySQL | daily.dev
og:description: VillageSQL Server's new vsql-oauth2 extension lets MySQL accounts authenticate using OAuth2/OpenID Connect JWTs instead of passwords, sourcing tokens from an...
og:url: https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7
og:image: https://api.daily.dev/og/posts/AsJMM5Kv7.png
og:image:alt: OAuth2 and JWT Logins for MySQL
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# OAuth2 and JWT Logins for MySQL

**[Planet MySQL](https://daily.dev/sources/planet-mysql)** · 9 min read · 0 upvotes · 0 comments

## Summary

VillageSQL Server's new vsql-oauth2 extension lets MySQL accounts authenticate using OAuth2/OpenID Connect JWTs instead of passwords, sourcing tokens from an identity provider like Microsoft Entra ID. It covers the basic setup (mapping a token to a pre-created proxy account) and role mapping (auto-creating accounts and granting MySQL roles based on App Roles in the token), removing manual password rotation and letting access follow single sign-on deprovisioning.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://villagesql.com/blog/oauth2>

## Questions this post answers

### How do I let users log into MySQL with an OAuth2 JWT instead of a password using the vsql-oauth2 extension?

Install the vsql_oauth2 extension on VillageSQL Server, then set vsql_oauth2.issuer, jwks_url, audience, and username_claim to match your identity provider. Create a proxy account bound to vsql_oauth2 and a target account, then grant proxy privileges between them. Users then pass a JWT as the MySQL password (via MYSQL_PWD) instead of a real password, and the server validates the token's signature against the provider's JWKS endpoint.

_Teams wiring OAuth2 into database access can track extension updates like vsql-oauth2 on daily.dev._

### How does automatic role mapping work when a new user logs into MySQL with an OAuth2 token for the first time?

Setting vsql_oauth2.roles_claim, roles_filter, roles_transform_pattern, roles_transform_replacement, auto_create, and auto_grant lets a brand-new user log in with a token carrying a roles claim (like App Roles from Entra ID) and automatically get a MySQL account plus the matching granted and activated role, with no prior CREATE USER by a DBA. auto_create handles users without accounts, auto_grant re-syncs roles for existing accounts on each login.

_Anyone automating database access provisioning from an identity provider can follow developments like this on daily.dev._

### What happens if I set both public_key and jwks_url in the vsql-oauth2 MySQL extension?

When both are set, jwks_url takes precedence over public_key. jwks_url points to the identity provider's key endpoint and lets the extension fetch and refresh signing keys automatically (hourly by default) so key rotation on the provider side does not break logins, whereas public_key pins a single key that stops working once the provider rotates it, making it suitable only for self-signed test setups.

_Engineers configuring token-based database auth can keep tabs on extensions like vsql-oauth2 via daily.dev._

## Similar posts on daily.dev

- [OpenID Connect Authentication for MySQL, Now Fully Open Source](https://daily.dev/posts/openid-connect-authentication-for-mysql-now-fully-open-source-4n4kv3qd8) · Planet MySQL · 0 upvotes · 0 comments
- [Introducing JWT authentication in ClickHouse Cloud](https://daily.dev/posts/introducing-jwt-authentication-in-clickhouse-cloud-x2whojuz6) · ClickHouse · 0 upvotes · 0 comments
- [Build "Sign in with Your App" using Supabase Auth](https://daily.dev/posts/build-sign-in-with-your-app-using-supabase-auth-u1r7btb2y) · Supabase · 5 upvotes · 0 comments
- [How to Secure APIs with OAuth 2.1 and OpenID Connect](https://daily.dev/posts/how-to-secure-apis-with-oauth-2-1-and-openid-connect-rf7g6orkv) · C\# Corner · 0 upvotes · 1 comments
- [Authorize, don't authenticate](https://daily.dev/posts/authorize-don-t-authenticate-7nbekvqkx) · Hacker News · 0 upvotes · 1 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#mysql](https://daily.dev/tags/mysql), [#jwt](https://daily.dev/tags/jwt)

[View this post on daily.dev](https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"OAuth2 and JWT Logins for MySQL","url":"https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7"},"datePublished":"2026-09-03T19:53:40.271Z","dateModified":"2026-09-03T23:40:34.427Z","description":"VillageSQL Server's new vsql-oauth2 extension lets MySQL accounts authenticate using OAuth2/OpenID Connect JWTs instead of passwords, sourcing tokens from an...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bf53dac194aa208a57075d2b5f1803c2?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/bf53dac194aa208a57075d2b5f1803c2?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet MySQL","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet MySQL","logo":"https://media.daily.dev/image/upload/s--UKAtmXTq--/f_auto,q_auto/v1780213421/logos/planet-mysql?_a=BAMAMiWQ0","url":"https://daily.dev/sources/planet-mysql"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,mysql,jwt","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet MySQL","item":"https://daily.dev/sources/planet-mysql"},{"@type":"ListItem","position":3,"name":"OAuth2 and JWT Logins for MySQL"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/oauth2-and-jwt-logins-for-mysql-asjmm5kv7#faq","mainEntity":[{"@type":"Question","name":"How do I let users log into MySQL with an OAuth2 JWT instead of a password using the vsql-oauth2 extension?","acceptedAnswer":{"@type":"Answer","text":"Install the vsql_oauth2 extension on VillageSQL Server, then set vsql_oauth2.issuer, jwks_url, audience, and username_claim to match your identity provider. Create a proxy account bound to vsql_oauth2 and a target account, then grant proxy privileges between them. Users then pass a JWT as the MySQL password (via MYSQL_PWD) instead of a real password, and the server validates the token's signature against the provider's JWKS endpoint. Teams wiring OAuth2 into database access can track extension updates like vsql-oauth2 on daily.dev."}},{"@type":"Question","name":"How does automatic role mapping work when a new user logs into MySQL with an OAuth2 token for the first time?","acceptedAnswer":{"@type":"Answer","text":"Setting vsql_oauth2.roles_claim, roles_filter, roles_transform_pattern, roles_transform_replacement, auto_create, and auto_grant lets a brand-new user log in with a token carrying a roles claim (like App Roles from Entra ID) and automatically get a MySQL account plus the matching granted and activated role, with no prior CREATE USER by a DBA. auto_create handles users without accounts, auto_grant re-syncs roles for existing accounts on each login. Anyone automating database access provisioning from an identity provider can follow developments like this on daily.dev."}},{"@type":"Question","name":"What happens if I set both public_key and jwks_url in the vsql-oauth2 MySQL extension?","acceptedAnswer":{"@type":"Answer","text":"When both are set, jwks_url takes precedence over public_key. jwks_url points to the identity provider's key endpoint and lets the extension fetch and refresh signing keys automatically (hourly by default) so key rotation on the provider side does not break logins, whereas public_key pins a single key that stops working once the provider rotates it, making it suitable only for self-signed test setups. Engineers configuring token-based database auth can keep tabs on extensions like vsql-oauth2 via daily.dev."}}]}
```

