-
Notifications
You must be signed in to change notification settings - Fork 20
Daming in 15 minutes
How to use Daming
to setup a sms pin micro service in 15 minutes
The basic idea of using daming
is adding its spring boot starter to your spring boot project.
The starter will import libraries and boot spring beans automatically.
With a few lines of configuration codes, you'll get a production ready sms verification feature.
- A blank Spring Boot 2 project, you may use Initializer to setup one
- A dependence management tool, such as gradle
- A local deployed Redis instance
- A private key for JWT, you may create your own, or use our demo private key(demo only, do NOT use it for production)
- Your favorite
IDE
, such as IntelliJ IDEA
# install daming
compile "com.github.hippoom:sms-verification-starter:${latestVersion}"
# use spring-data-redis 2.x
compile "org.springframework.data:spring-data-redis:2.1.2.RELEASE"
- Configuration
The following configurations are required to makeDaming
work, you can usespring-boot
profile or environment variables:
# src/main/resources/application.properties
# setup sms verification scopes
daming.sms.verification.scope.valid=DEMO
# setup private key to sign JWT
daming.jwt.key.file=/home/your-app/sms-verification-private.der
- Boot your application
Daming
is ready, start yourspring-boot
application now!
Open your favorite terminal, type the request as following:
curl -v -H 'Content-Type:application/json;charset=UTF-8' -XPOST localhost:8080/api/sms/verification/code -d '{"mobile": "your-mobile-phone-number", "scope": "DEMO"}'
Daming
will print the PIN on the console instead of sending a real sms by default (to save your money):
c.t.d.sms.SmsVerificationCodeSenderStub : Sending [DEMO] code 262843 to [your-mobile-phone-number], the code is expiring in PT1M
Extract your PIN(6 bit digits) after code
Open your favorite terminal, type the request as following:
curl -v -H 'Content-Type:application/json;charset=UTF-8' -XDELETE localhost:8080/api/sms/verification/code -d '{"mobile": "your-mobile-phone-number", "scope": "DEMO", "code": "the code"}'
You shall see similar outputs like this:
{"token":"eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJ2ZXJpZmllZE1vYmlsZVBob25lTnVtYmVyIiwibW9iaWxlIjoiMTM5MTc3Nzc3NjMiLCJzY29wZSI6IkRFTU8iLCJleHAiOjE1NjAyNjgzNjV9.hAmB725zVor3mu0lCNlyIjdvnmaRhFmoVRdJUUUMHEEXFo2lBRTlV_1Te02Br0_Juz8gnpAW-8rtVptaFV3fIYogd-T4pVQw4ahXnWV7u_pOkLZLdvOg38v2WRL6YOYDAF1EoFqJU5unnG6bgCFY3dfQFOuggExyPoUUV6ZLh7pvNuDz-fhGzjH9fVrpC9zuxjUU_EHxXxqGg-FTyB9cprqorNdYUvoHJcWSeGUjvVhiSMdn_QqetYFECPyWsFaL7uDtNbBP3ePD-17jcJg_QG1S9mwtnOaD4tNgR0muKbzxoNP7Wzn6BpuQ0dKk-aLzJ5sIMcJ_ZFa5ysB1mDTCRA"}
Decode this token
(you can use https://jwt.io/), you shall see
{
"sub": "verifiedMobilePhoneNumber",
"mobile": "your-mobile-phone-number",
"scope": "DEMO",
"exp": 1560268365
}
It means Daming
has verified the PIN is for mobile
with scope
, and the token is valid before exp
.
Congratulations, you have implement SMS PIN feature within just 15 minutes without written any code!
TODO: translation the following: 另一方面,如果您有以下疑惑:
- 快速入门
- 文档
- 为什么要开发Daming
- 集成模式
- 安装Daming
- Sms Verification Scope
- 集成短信供应商
- 什么是Sms Verification JWT
- API
- 非生产环境支持
- 防止验证码暴力破解
- 验证码发送限流
- 设置验证码有效期
- 微服务模式的SDK (TBD)
- 已知问题
- 示例
- 变更历史(TBD)