1.0.1 • Published 4 years ago

@uni/authorize v1.0.1

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
4 years ago

authorize

npm

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.

Supported

Install

$ npm install @uni/authorize --save

or

$ npm install @uni/apis --save

Usage

import authorize from '@uni/authorize';

authorize({
  scope: 'scope.userLocation',
  success: () => {
    console.log('success');
  },
  fail: (res) => {
    console.log('fail', res);
  },
  complete: (res) => {
    console.log('complete', res);
  }
});

authorize({
  scope: 'scope.userLocation',
}).then((res?) => {
  console.log('success');
});

你也可以从大包引入:

import { authorize } from '@uni/apis';

Parameters

PropertyTypeDescriptionRequiredDefault
optionsobject -
options.scopestring The scope to be authorized. For details, see scope listYes-
options.successFunction The callback function for a successful API callNo-
options.failFunction The callback function for a failed API callNo-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)No-

Scope List

scopeDescriptionCorresponding APIsSupported
scope.userInfoUser informationgetUserInfo, getOpenUserInfo
scope.userLocationGeographic locationgetLocation, chooseLocation
scope.userLocationBackgroundBackground positioningstartLocationUpdateBackground
scope.werunWeRun step countsgetWeRunData
scope.recordRecording featurestartRecord
scope.writePhotosAlbumSaves to albumsaveImage, saveVideo
scope.cameraCamerascanCode,chooseImage,chooseVideo
scope.calendarcalendaraddEventOnCalendar,deleteEventOnCalendar
auth_baseSilent authorization will not initiate authorization floating window. Get auth from Alipay client Code, the incoming server invokes the alipay.system.oauth.token interface to get Alipay membership identifier (user). id)addEventOnCalendar,deleteEventOnCalendar
auth_zhimaUser sesame informationzhima.credit.score.brief.get

Response<Response>(Not general)

Note: only Alipay applet returns.

PropertyTypeDescription
responseobject-
response.authCodestring Authorization code
response.authErrorScopesobject Failed authorization type. Key is the scope of failed authorization, and value is the corresponding error code
response.authSuccessScopesArray Successful authorization scope