Skip to main content

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​

  1. 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:

  2. 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).

  3. 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 situationUse
Your app has a login and holds the customers' credentialsYour own login, with a sign-in token or an identity token
Your app has no login and you want customers to sign inBlack's sign-in, one or more methods
You want no password to keep or resetThe email link or Google
You want a passwordEmail and password

Turn on a method of Black's sign-in​

  1. Turn the method on. Send a PATCH request to /v1/settings with the method inside sign_in: password, email_link or google. Each is on its own, and all are off in a new environment. A call to a method that is off answers 403 with sign_in_method_disabled. See Change an environment's settings.

  2. Turn on Google with its client ID. Send google_client_id, your own Google client ID, with google set to true. Black holds no Google secret. Without the client ID the request answers 422 with parameter_invalid, naming sign_in.google_client_id.

Tell a page where your own sign-in is​

  1. Set sign_in.own_sign_in_url. Send a PATCH request to /v1/settings with {"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 answers 422 with parameter_invalid, naming sign_in.own_sign_in_url. Send null to clear it.

  2. Read it from the page. Send a GET request to /v1/client/config with the publishable key. The sign_in object of the response holds methods, the methods of Black's own sign-in that are on, in the order password, email_link, google (an empty list while all are off), google_client_id while Google is offered, and own_sign_in_url. A page shows a button for each method in methods, and sends the customer to own_sign_in_url when 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​