send_email_through_keyclock
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| send_email_through_keyclock [2026/03/09 05:18] – sonali | send_email_through_keyclock [2026/03/09 08:00] (current) – sonali | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | < | ||
| + | |||
| + | A system where users can log in using their **email Id /Username + Email OTP** instead of username/ | ||
| + | |||
| + | **Make Email OTP Java SPI ** | ||
| + | |||
| # Run this to find the Keycloak container: | # Run this to find the Keycloak container: | ||
| Line 20: | Line 26: | ||
| We need email-otp-authenticator JAR if it is not available | We need email-otp-authenticator JAR if it is not available | ||
| - | 1. Download the email-otp-authenticator JAR | + | **1. Download the email-otp-authenticator JAR** |
| < | < | ||
| Line 27: | Line 33: | ||
| </ | </ | ||
| - | 2. Copy into the running container | + | **2. Copy into the running container** |
| < | < | ||
| docker cp email-otp-authenticator.jar keycloak_app:/ | docker cp email-otp-authenticator.jar keycloak_app:/ | ||
| Line 34: | Line 39: | ||
| </ | </ | ||
| - | 3. Run build inside the container (registers the provider) | + | **3. Run build inside the container (registers the provider)** |
| + | < | ||
| + | # Verify it's there | ||
| + | docker exec keycloak_app ls / | ||
| + | |||
| + | </ | ||
| < | < | ||
| Line 41: | Line 51: | ||
| </ | </ | ||
| - | 4. Restart the container | + | **4. Restart the container** |
| + | < | ||
| + | docker restart keycloak_app | ||
| - | < | ||
| </ | </ | ||
| + | |||
| + | # Now let's set up the Email OTP flow. Go to Keycloak Admin Console at [[https:// | ||
| + | |||
| + | **1. First configure SMTP (if not already done)** | ||
| + | |||
| + | Realm Settings → Email | ||
| + | |||
| + | Host: smtp.gmail.com, | ||
| + | |||
| + | Port: 587 | ||
| + | |||
| + | From: from email id | ||
| + | |||
| + | Username: your username, | ||
| + | |||
| + | Password: your app | ||
| + | |||
| + | password Enable StartTLS → Save → Test connection | ||
| + | |||
| + | **2. Create Email OTP Authentication Flow** | ||
| + | < | ||
| + | |||
| + | Go to Authentication → Flows → Create flow Name: Browser Email OTP | ||
| + | → Save Add step → Username Password Form → Required Add step → | ||
| + | Email OTP → Required | ||
| + | |||
| + | </ | ||
| + | |||
| + | **3. Bind the flow** | ||
| + | |||
| + | Client → account → Advance Override realm authentication flow bindings. →Browser Flow → Browser email otp | ||
| + | |||
| + | **Customize email content** | ||
| + | < | ||
| + | python3 -c " | ||
| + | |||
| + | </ | ||
| + | |||
| + | # check current email template | ||
| + | |||
| + | < | ||
| + | python3 -c " | ||
| + | import zipfile | ||
| + | with zipfile.ZipFile(' | ||
| + | print(z.read(' | ||
| + | " | ||
| + | |||
| + | </ | ||
| + | |||
| + | # To customize the email text, create a custom Keycloak theme. Run these commands on the droplet: | ||
| + | |||
| + | Step 1: Create theme directory \structure | ||
| + | |||
| + | < | ||
| + | docker exec keycloak_app mkdir -p / | ||
| + | |||
| + | </ | ||
| + | |||
| + | Step 2: Create theme.\properties | ||
| + | |||
| + | < | ||
| + | docker exec keycloak_app sh -c ' | ||
| + | parent=\base | ||
| + | EOF' | ||
| + | |||
| + | </ | ||
| + | |||
| + | Step 3: Create custom messages (edit the text as you like) | ||
| + | |||
| + | < | ||
| + | docker exec keycloak_app sh -c ' | ||
| + | emailOtpSubject=Your Cotrav OTP \Code | ||
| + | emailOtpYourAccessCode=Your one-time login code is: | ||
| + | emailOtpExpiration=This code will expire in {0} minutes. Do not share it with anyone. | ||
| + | EOF' | ||
| + | |||
| + | </ | ||
| + | |||
| + | Step 4: Set realm to use this \theme | ||
| + | |||
| + | < | ||
| + | TOKEN=$(curl -s -X POST http:// | ||
| + | -d " | ||
| + | | grep -o '" | ||
| + | |||
| + | curl -s -X PUT http:// | ||
| + | -H " | ||
| + | -H " | ||
| + | -d ' | ||
| + | |||
| + | </ | ||
| + | |||
| + | Then test by logging in again — you should see your custom text in the OTP email. | ||
| + | |||
| + | # Invalid otp issue\\ | ||
| + | The OTP field name sent by our server might not match what the extension expects. Let me check: | ||
| + | < | ||
| + | |||
| + | python3 -c "\ | ||
| + | import zipfile\ | ||
| + | with zipfile.ZipFile(' | ||
| + | print(z.read(' | ||
| + | " | ||
| + | |||
| + | </ | ||
| + | |||
| + | **# Browser email otp Flow order should be** \\ | ||
| + | Username Form → Required (first)\\ | ||
| + | Email OTP Form → Required (second) | ||
| + | |||
| + | **# Dont do this** | ||
| + | |||
| + | - No required user action available in user details\\ | ||
| + | - Set Email & password | ||
send_email_through_keyclock.1773033516.txt.gz · Last modified: by sonali
