# Authorization

Some of the APIs need users’ authorization before they can be called. We have divided these APIs into multiple scope according to the scope of usage. The users can select scope to authorize. After a scope is authorized, all of its APIs can be used directly.

When such an API is called:

  • If the user has not accepted or rejected this authorization, a pop-up window will appear to ask the user if he/she wants to accept. The API can be called only after the user clicks to accept;
  • If the user has accepted authorization, the API can be called directly;
  • If the user has rejected authorization, no pop-up appears. Instead, API fail callback will be accessed directly. Developers should make the scenario compatible where the user has rejected to authorization.

# Obtain User Authorization Settings

The developer can use wx.getSetting to get the user's current authorization state.

# Go to Settings

The user can control the authorization state of the Mini Program in Mini Program Settings by clicking About in the upper right and then Settings in the upper right.

The developer can call wx.openSetting to open Settings, and guide the user to enable authorization.

# Initiate the Authorization Request in Advance

The developer can use wx.authorize to initiate the authorization request to the user in advance before calling the API to authorize.

# Scope List

scope Corresponding APIs Description
scope.userInfo wx.getUserInfo User information
scope.userLocation wx.getLocation, wx.chooseLocation Geographic location
scope.address wx.chooseAddress Postal address
scope.invoiceTitle wx.chooseInvoiceTitle Invoice title
scope.invoice wx.chooseInvoice Gets invoice
scope.werun wx.getWeRunData WeRun step counts
scope.record wx.startRecord Recording feature
scope.writePhotosAlbum wx.saveImageToPhotosAlbum, wx.saveVideoToPhotosAlbum Saves to album
scope.camera camera Component Camera

# Period of Validity

Once the user explicitly agrees or rejects authorization, his/her authorization relationship will be recorded in the backend, until the user deletes the Mini Program.

# Best Practices

Initiate an authorization request to the user only when the authorization API is needed, and clearly explain the reason why you want to use it in the authorization request.

# Notes

  1. wx.authorize({scope: "scope.userInfo"}) will not pop up the authorization window. Use <button open-type="getUserInfo"/>
  2. When scope.userLocation authorization is needed, it is necessary to configure a usage description for geographical location.