Viewing Conditions - Independent Authorization
1. Configuration Information
1.1 Independent Authorization Configuration Information
For details on independent authorization settings and server-side processing flow, please refer to the help center documentation: Independent Authorization
Interface: AuthSettingItemDirect
| Property Name | Description | Type |
|---|---|---|
authType |
Condition Type | Direct |
enabled |
Enabled | null | YN |
directRedirectUri |
Authorization Failure Redirect URL | string |
2. Usage
2.1 Allow Verification of Independent Authorization
After redirecting back to the viewing page from the authorization platform, use this method to determine whether the current environment allows independent authorization signature verification.
Starting from version v0.11.0, when authorization passes but other configurations are normal, external authorization signature verification is also allowed. Additionally, through the new options parameter, developers can set
{ ignoreAuthorized:false }to achieve the same effect as previous versions.
Api Method: allowToVerifyDirectAuth(signParams: DirectAuthSignParams, options?: Object): Promise<boolean>
Parameter Description:
- signParams: Authorization signature parameters, type
DirectAuthSignParams, required. Detailed type description is as follows:
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
userid |
User ID | string |
Yes | - |
ts |
Timestamp | string |
Yes | - |
sign |
Authorization Signature | string |
Yes | - |
nickname |
User Nickname | string |
Yes | - |
- options: Configuration items, type
Object, optional. Detailed type description is as follows:
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
ignoreAuthorized |
Ignore authorization status, default true | boolean |
No | - |
Return Value Description: Whether independent authorization verification is allowed, type Promise<boolean>
Example:
import { parse } from '@polyv/utils/querystring';
import { DirectAuthSignParams } from '@polyv/live-watch-sdk';
async function example {
const queryParams = parse(window.location.search.slice(1));
const signParams: DirectAuthSignParams = {
userid: queryParams.userid || '',
ts: queryParams.ts || '',
sign: queryParams.sign || '',
nickname: queryParams.nickname || '',
};
const allowVerify = watchCore.auth.allowToVerifyDirectAuth(signParams);
if (allowVerify) {
// TODO 验证独立授权
}
}
2.2 Verify Independent Authorization Signature Parameters
After redirecting back to the viewing page from the authorization platform, use verifyDirectAuth to verify the external authorization signature parameters. Before calling, invoke allowToVerifyDirectAuth to check whether the signature parameters meet the requirements.
Api Method: verifyDirectAuth(signParams: DirectAuthSignParams, queryParams: object): Promise<VerifyDirectAuthResult>
Parameter Description:
- signParams: Authorization parameters, type
DirectAuthSignParams, required. Detailed type description is as follows:
| Parameter Name | Description | Type | Required | Default Value |
|---|---|---|---|---|
userid |
User ID | string |
Yes | - |
ts |
Timestamp | string |
Yes | - |
sign |
Authorization Signature | string |
Yes | - |
nickname |
User Nickname | string |
Yes | - |
- queryParams: Link parameters, type
object, required
Return Value Description: Type Promise<VerifyDirectAuthResult>
Example:
import { parse } from '@polyv/utils/querystring';
import { ExternalAuthSignParams } from '@polyv/live-watch-sdk';
async function example {
const queryParams = parse(window.location.search.slice(1));
const signParams: ExternalAuthSignParams = {
userid: queryParams.userid || '',
ts: queryParams.ts || '',
sign: queryParams.sign || '',
nickname: queryParams.nickname || '',
};
const allowVerify = watchCore.auth.allowToVerifyDirectAuth(signParams);
if (!allowVerify) {
return;
}
const result = await watchCore.auth.verifyDirectAuth(signParams, queryParams);
if (result.success) {
handleAuthVerifySuccess(result);
} else {
handleAuthVerifyFail(result);
}
}
2.3 Allow Automatic Redirect to Independent Authorization Failure Page
When independent authorization fails or the viewing page URL lacks independent authorization signature parameters, use the allowAutoRedirectDirectAuthFailUrl method to determine whether to automatically redirect to the independent authorization failure page. Internal judgment conditions are as follows:
- The viewer is not authorized
- Only independent authorization is set in the admin backend
Api Method: allowAutoRedirectDirectAuthFailUrl(): Promise<boolean>
Return Value Description: Whether to automatically redirect, type Promise<boolean>
Example:
// 验证独立授权失败之后 / 无独立授权签名参数
const allowAutoRedirect = await watchCore.auth.allowAutoRedirectDirectAuthFailUrl();
if (allowAutoRedirect) {
watchCore.auth.redirectDirectAuthFailUrl();
}
2.4 Get Independent Authorization Failure URL
Api Method: getDirectAuthFailUrl(): Promise<DirectAuthFailUrlData>
Since v2.5.0
When independent authorization fails or the viewing page URL lacks independent authorization signature parameters, use this method to obtain the custom authorization failure URL and redirect. Supported from this version.
Return Value Description: Independent authorization failure URL information, type Promise<DirectAuthFailUrlData>. Detailed type description is as follows:
| Property Name | Description | Type |
|---|---|---|
directAuthFailUrl |
Independent Authorization Failure Redirect URL | undefined | string |
Example:
document.querySelector('button').addEvenListener('click', async () => {
const data = await watchCore.auth.getDirectAuthFailUrl();
window.location.href = data.directAuthFailUrl;
});
2.5 Redirect to Independent Authorization Failure URL
Api Method: redirectDirectAuthFailUrl(): Promise<boolean>
Since v2.5.0 If you do not call
getDirectAuthFailUrlto get the redirect URL, developers can callredirectDirectAuthFailUrlto perform the redirect and determine whether the page was redirected based on the method's return result. Supported from this version.
Return Value Description: Whether the redirect occurred, type Promise<boolean>
Example:
const result = await watchCore.auth.redirectDirectAuthFailUrl();
if (result) {
console.log('页面已重定向');
} else {
console.log('重定向失败');
}
