upnext / BeaconControl

Setup and manage large beacon deployments with BeaconControl open source platform
https://beaconcontrol.io
BSD 3-Clause "New" or "Revised" License
92 stars 63 forks source link

s2s api : how to create a user without using the UI #48

Open mhd999 opened 7 years ago

mhd999 commented 7 years ago

Hi!

Am trying to use the s2s api to create applications for now, As i understood from the docs we need access_token to authenticate the request which it can be fetched from this api /s2s_api/v1/oauth/token however i need to create the user using the UI first and wondering if this can be done through the api.

Minty123 commented 7 years ago

Hi mhd999!

See the following steps to create an admin user through the API. With it, you don't need a token, but just a clientID/clientSecret.

1. Get your clientID and clientSecret

(see https://beaconcontrol.io/dev/backend/s2s_api_docs_v1/index.html)

To get client_id and client_secret execute one of the following commands: SQL: select uid, secret from oauth_applications where owner_type = 'Brand'; rails console: Doorkeeper::Application.where(owner_type: 'Brand').select(:uid, :secret).first

2. Make a post request for the new user

(see https://beaconcontrol.io/dev/backend/s2s_api_docs_v1/registration.html)

URL: e.g. http://server:port/s2s_api/v1/admins Request Body:

{
  "client_id":    "your-client-id",
  "client_secret":"your-client-secret",
  "admin": {
    "email":           "new-admin@example.com",
    "password":        "new-pw"
  }

You could now go ahead and create a Token for this new user. Hope this helps you or any other ppl who stumble upon this!