cooperlyt / keycloak-phone-provider

A Keycloak provider for phone and SMS
MIT License
286 stars 159 forks source link

Cant register user , sms provider not set #37

Closed kowiste closed 1 year ago

kowiste commented 1 year ago

Im trying to use an twilio account and start keycloak with this configuration

version: '3'
services:

  database:
    image: mariadb:latest
#    restart: always
    ports:
      - "3306:3306"
#    volumes:
#      - "/home/data/db:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: p0stgr@s
      MYSQL_DATABASE: keycloak
      MYSQL_USER: keycloak
      MYSQL_PASSWORD: k@ycl0ck
      TZ: Asia/Shanghai

  keycloak:
    image: coopersoft/keycloak:21.0.1_phone-2.2.2
    #    restart: always
    ports:
      - 8080:8080
    command:
      - start-dev --spi-phone-message-service-default-service=dummy
    environment:
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KC_HEALTH_ENABLED: true
      KC_PROXY: edge
      SMS_PROVIDER_SERVER: twilio
      SMS_TOKEN_EXPIRES: 180
      SMS_HOUR_MAXIMUM: 3
      TWILIO_ACCOUNT_ID: "A000000000000"
      TWILIO_AUTH_TOKEN:  "c91e000000080b5"
      TWILIO_SEND_PHONE_NUMBER: "00000000"
      DB_VENDOR: mariadb
      DB_ADDR: database
      DB_DATABASE: keycloak
      DB_USER: keycloak
      DB_PASSWORD: k@ycl0ck
      DB_PORT: 3306
    links:
      - database:database
    depends_on:
      - database

Create the flow and when I try to send the code I can see this in the log

not specify a message sender service provider! Default provider'dummy' will be used. you can use keycloak start param '--spi-phone-default-service' specify other one.

Can I use the environment variable like that? Do I have to do something more?

cooperlyt commented 1 year ago

command replace to start-dev --spi-phone-default-service=aws

kowiste commented 1 year ago

Thanks, but now is having this error

2023-03-27 13:01:22,810 ERROR [org.keycloak.services.error.KeycloakErrorHandler](executor-thread-0) Uncaught server error: com.twilio.exception.AuthenticationException: Username can not be null
2023-03-27 15:01:22     at com.twilio.Twilio.setUsername(Twilio.java:88)
2023-03-27 15:01:22     at com.twilio.Twilio.init(Twilio.java:62)
2023-03-27 15:01:22     at cc.coopersoft.keycloak.phone.providers.sender.TwilioSmsSenderServiceProvider.<init>(TwilioSmsSenderServiceProvider.java:18)
2023-03-27 15:01:22     at cc.coopersoft.keycloak.phone.providers.sender.TwilioMessageSenderServiceProviderFactory.create(TwilioMessageSenderServiceProviderFactory.java:15)
2023-03-27 15:01:22     at cc.coopersoft.keycloak.phone.providers.sender.TwilioMessageSenderServiceProviderFactory.create(TwilioMessageSenderServiceProviderFactory.java:9)
2023-03-27 15:01:22     at org.keycloak.services.DefaultKeycloakSession.getProvider(DefaultKeycloakSession.java:288)
2023-03-27 15:01:22     at cc.coopersoft.keycloak.phone.providers.spi.impl.DefaultPhoneProvider.sendTokenCode(DefaultPhoneProvider.java:97)
2023-03-27 15:01:22     at cc.coopersoft.keycloak.phone.providers.rest.TokenCodeResource.getTokenCode(TokenCodeResource.java:53)

Which is the username? and how can i set it? enviroment variable, command?

cooperlyt commented 1 year ago

this is Twilio jar Exception. need set account.

Refer: twilio config readme

if you valid on twilio ,tell me, please

RossRogers commented 1 year ago

Your command should look something like:

    command:
      - start-dev
      - --spi-phone-default-service=twilio
      - --spi-message-sender-service-twilio-account=DEAD123789z931...
      - --spi-message-sender-service-twilio-token=dead1234789...
      - --spi-message-sender-service-twilio-number=+1888...

--spi-phone-message-service-default-service=dummy is wrong. There was a bug in the documentation.