SAPWebSocketAuthenticationObserver
public class SAPWebSocketAuthenticationObserver
extension SAPWebSocketAuthenticationObserver: SAPURLSessionObserving
An observer that handles unauthorized WebSocket requests.
SAPWebSocketAuthenticationObserver monitors WebSocket requests and responses.
When an unauthorized request is detected, the observer uses the provided SAPWebSocketAuthenticationHandling implementation
to obtain a valid OAuth 2.0 access token and enables reauthorization of the webSocket connection.
-
Error cases that may happen when obtaining OAuth 2 token.
See moreDeclaration
Swift
public enum Failure : SAPError -
Designated initializer
Declaration
Swift
public init(authenticationHandler: SAPJouleAuthenticationHandler, tokenStore: OAuth2TokenStore?, remoteUrl: URL)Parameters
authenticationHandlerAn instance conforming to
SAPJouleAuthenticationHandlertokenStoreAn optional
OAuth2TokenStoreused to persist the obtained OAuth 2.0 token. If nil a web service call is made everytime to obtain the token.remoteUrlThe remote URL for which the obtained OAuth 2.0 token is stored in the token store.
-
Here an unauthorised web socket request is detected and OAuth 2.0 token is obtained either from local store or from
SAPJouleAuthenticationHandler. Does nothing if the request is not a web socket requet or if the request is already authorised.Declaration
Swift
public func sapURLSession(_ session: SAPURLSession, task: SAPURLSessionTask, willSend request: URLRequest, completionHandler: @escaping (SAPURLSession.RequestDisposition) -> Void)