new AuthHandler(session)
Parameters:
Name | Type | Description |
---|---|---|
session |
wsc.Session | An instance of the wsc.Session object. |
Example
var authHandler = new wsc.AuthHandler(wscSession);
authHandler.refresh = refreshAuth
function refreshAuth(authType, authHeaders){
var authInfo = null;
if(authType==wsc.AUTHTYPE.SERVICE) {
// Return a JSON object according to the content of the "authHeaders". authInfo = ...; } else if(authType==wsc.AUTHTYPE.TURN) {
// Return a JSON object formatted like this: {"iceServers" : [ {"url":"turn:test@: ", "credential":" "} ]}. authInfo = ...;
}
return authInfo;
};
Following is an authHeaders sample for Digest authentication:
{ "scheme": "Digest", "nonce": "a12e8f74-af01-4e74-9714-4d65bae4e024", "realm": "example.com", "qop": "auth", "challenge_code": "407", "opaque": "YXBwLTNjOHFlaHR2eGRhcnxiYWNkMTIxMWFmZDlkNmUyMThmZmI0ZDc4ZmY3ZmY1YUAxMC4xODIuMTMuMTh8Mzc3N2E3Nzc0ODYyMGY4", "charset": "utf-8", "method": "REGISTER", "uri": "sip:10.182.12.165:5060" } Digest authentication is fully described in RFC 2617.
Events
-
refresh
-
The callback function to handle the authentication event.
Parameters:
Name Type Description authType
String the authentication type.
authHeaders
Object the headers that used for the authentication. For both wsc.AUTHTYPE.TURN and wsc.AUTHTYPE.SERVICE, there is not headers and it is passed as null.
Returns:
if authType is wsc.AUTHTYPE.SERVICE, then {"username": yourUsername, "password": yourPassword} should be returned; if authType is wsc.AUTHTYPE.TURN, then {"iceServers": [iceServer1, iceServer2, ...]} should be returned. Here are two examples. Return {"username": "admin", "password": "admin"} for wsc.AUTHTYPE.SERVICE. Return {"iceServers": [{"url":"turn:10.182.13.232:3478", "credential":"sips", "username":"admin"}]} for wsc.AUTHTYPE.TURN.
- Type
- Object