/send_code
and /verify
.
Clients of this service will use the /send_code
endpoint to request the verification of a phone number. The phone number referenced here will receive a SMS message with the verification code. Then a second call to /verify
including the phone number and the received verification code will validate that the code is correct and, if so, a user is created or authenticated (if they already exist) in Firebase Auth.
go mod init example.com/prelude-firebase-integration
go get github.com/prelude-so/go-sdk
go get firebase.google.com/go/v4@latest
server.go
file in the same directory where we created the Go module, use it as our main entry point, and add the required imports and constants at the top of the file:
server.go
file to contain everything in this example so we are adding a main
function in it that will configure the HTTP server and the 2 required endpoints.
/send_code
and /verify
) which will subsequently call the functions described below./send_code
endpoint. To achieve this, a client application should issue a POST HTTP request with the following structure:
phone_number
represents a E.164 formatted mobile phone number. For instance, a French mobile number would be formatted as: +33XXXXXXXXX
.
Upon receiving such a request, the server will invoke the SendCode
function, which will be outlined next:
preludeClient.Verification.New
function with it. If the Prelude client is correctly configured with the API key, a verification code will be sent to the requested phone number. In the success scenario (happy path) this function just returns a HTTP 204 status code.
/verify
endpoint of the server to verify that the code is correct. The expected request for this endpoint has the following shape:
phone_number
field plus a new code
field that should be filled with the verification code received in the phone (from 4 to 8 digits code).
Once the endpoint receives the request, it will call the Check
function:
preludeClient.Verification.Check
function from the Prelude Go SDK with those parameters. Here we can simply examine the returned result and if it is a successful result (prelude.VerificationCheckResponseStatusSuccess
) we can proceed to create or authenticate the user in Firebase. For that we will use the CreateFirebaseUser
function.