Choose how customers sign in
What you will build
You choose how your customers sign in to your page or app, and set the sign-in settings that match. At the end the environment's configuration tells a page which sign-in to show.
Both ways end the same: the customer holds a session of the Client API. See Start, refresh and end a customer session for what a session is.
Before you start
You need an app with a publishable key in the environment: see Manage an app's keys and allowed origins. The settings are changed by the account's own API client, or by its vendor with Black-Account: see Change account settings.
Steps
Choose between Black's sign-in and your own
-
Use your own login when your app already knows who its customers are. Your login keeps the passwords, the single sign-on and the second factor, and tells Black who signed in. Choose one of two ways:
- Your server makes a one-time sign-in token and the page exchanges it: see Start, refresh and end a customer session.
- Your login signs an identity token and the page exchanges it: see Sign customers in with your own sign-in.
-
Use Black's sign-in when your app has no login of its own, or when you want no password to keep. Black keeps the credentials, sends the emails and ends the sessions. Turn on each method on its own: email and password (Sign customers in with email and password), a link sent by email (Sign customers in with an email link) and Google (Sign customers in with Google).
-
Keep one way for one group of customers. A customer your server or your own login made is found by your own reference, and Black's sign-in never links them by email: see Know how Black matches a customer. Two ways for one person make two customers.
| Your situation | Use |
|---|---|
| Your app has a login and holds the customers' credentials | Your own login, with a sign-in token or an identity token |
| Your app has no login and you want customers to sign in | Black's sign-in, one or more methods |
| You want no password to keep or reset | The email link or Google |
| You want a password | Email and password |
Turn on a method of Black's sign-in
-
Turn the method on. Send a
PATCHrequest to/v1/settingswith the method insidesign_in:password,email_linkorgoogle. Each is on its own, and all are off in a new environment. A call to a method that is off answers403withsign_in_method_disabled. See Change an environment's settings. -
Turn on Google with its client ID. Send
google_client_id, your own Google client ID, withgoogleset totrue. Black holds no Google secret. Without the client ID the request answers422withparameter_invalid, namingsign_in.google_client_id.
Tell a page where your own sign-in is
-
Set
sign_in.own_sign_in_url. Send aPATCHrequest to/v1/settingswith{"sign_in":{"own_sign_in_url":"https://app.example.com/login"}}. It is the HTTPS address of your own sign-in page. An address that is not HTTPS answers422withparameter_invalid, namingsign_in.own_sign_in_url. Sendnullto clear it. -
Read it from the page. Send a
GETrequest to/v1/client/configwith the publishable key. Thesign_inobject of the response holdsmethods, the methods of Black's own sign-in that are on, in the orderpassword,email_link,google(an empty list while all are off),google_client_idwhile Google is offered, andown_sign_in_url. A page shows a button for each method inmethods, and sends the customer toown_sign_in_urlwhen you set it. Black does not open that address itself. See Show the environment's configuration.
The answer is kept for up to five minutes by a browser. A page that must see a change at once reads it again after that time.
A runnable sample
This sample registers an app and its key, turns on the email link method, sets the address of your own sign-in, reads the configuration as a page does, then clears both settings. It writes PLACEHOLDER_ACCESS_TOKEN where your access token goes, reads the app's ID and the key from the responses, and needs sed. Each write waits a second because a test environment takes five writes a second.
TOKEN=PLACEHOLDER_ACCESS_TOKEN
APP=$(curl --silent --request POST https://api.black.example/v1/apps \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--data '{"name":"Choice Demo","kind":"web","allowed_origins":["https://app.example.com"]}' \
| sed -n 's/.*"id":"\(app_[0-9a-z]*\)".*/\1/p')
sleep 1
KEY=$(curl --silent --request POST "https://api.black.example/v1/apps/$APP/publishable-keys" \
--header "Authorization: Bearer $TOKEN" \
| sed -n 's/.*"\(pk_test_[0-9A-Za-z]*\)".*/\1/p')
sleep 1
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--data '{"sign_in":{"email_link":true,"own_sign_in_url":"https://app.example.com/login"}}'
sleep 1
curl --silent --request GET https://api.black.example/v1/client/config \
--header "Black-Publishable-Key: $KEY" \
--header "Origin: https://app.example.com"
curl --silent --request PATCH https://api.black.example/v1/settings \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/json" \
--data '{"sign_in":{"email_link":false,"own_sign_in_url":null}}'
The app and its key answer 201. The first settings change answers 200. The configuration read answers 200 and its sign_in holds email_link in methods and the address you set. The last change answers 200 and clears both.
What to do next
- Read how Black matches a customer who signs in in more than one way in Know how Black matches a customer.
- Read each method's guide: email and password, an email link and Google.
- Read how to change settings in Change account settings.
- Read every error code in Errors.