Server

Representing the FHIR resource server a client connects to.

This implementation holds on to an Auth instance to handle authentication. It is automatically instantiated with properties from the settings dictionary provided upon Client initalization or from the server’s cabability statement.

The server’s cabability statement is automatically downloaded the first time it’s needed for various tasks, such as instantiating the Auth instance or validating/executing operations.

A server manages its own NSURLSession, either with an optional delegate provided via sessionDelegate or simply the system shared session. Subclasses can change this behavior by overriding createDefaultSession or any of the other request-related methods.

  • aud

    The service URL as a string, as specified during initalization to be used as aud parameter.

    Declaration

    Swift

    public final let aud: String
  • An optional name of the server; will be read from cabability statement unless manually assigned.

    Declaration

    Swift

    public final var name: String?
  • An optional NSURLSessionDelegate.

    Declaration

    Swift

    open var sessionDelegate: URLSessionDelegate?
  • Allow to inject a custom OAuth2DynReg class and/or setup.

    Declaration

    Swift

    open var onBeforeDynamicClientRegistration: ((URL) -> OAuth2DynReg)?
  • The logger to use.

    Declaration

    Swift

    open var logger: OAuth2Logger?
  • Main initializer. Makes sure the base URL ends with a / to facilitate URL generation later on.

    Declaration

    Swift

    public required init(baseURL base: URL, auth: OAuth2JSON? = nil)

    Parameters

    baseURL

    The base URL of the server

    auth

    A dictionary with authentication settings, passed on to the Auth initializer

  • Instantiate the server’s default URLSession.

    Declaration

    Swift

    override open func createDefaultSession() -> URLSession

    Return Value

    The URLSession created

  • Return a URLRequest for the given url, possibly already signed, that can be further configured.

    Declaration

    Swift

    override open func configurableRequest(for url: URL) -> URLRequest

    Parameters

    url

    The URL the request will work against

    Return Value

    A preconfigured URLRequest

  • Declaration

    Swift

    open override func perform(request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionTask?

    Parameters

    request

    The URL request to perform as-is

    completionHandler

    The completion handler, returning optional data, response and error instances, when all has completed

    Return Value

    A URLSessionTask that is already under way

  • The auth credentials currently in use by the receiver.

    Declaration

    Swift

    open var authClientCredentials: (id: String, secret: String?, name: String?)?
  • Ensures that the server is ready to perform requests before calling the callback.

    Being ready in this case entails holding on to an Auth instance. Such an instance is automatically created if either the client init settings are sufficient (i.e. contain an authorize_uri and optionally a token_uri and a client_id or registration_uri) or after the cabability statement has been fetched.

    Declaration

    Swift

    open func ready(callback: @escaping (FHIRError?) -> ())
  • Ensures that the receiver is ready, then calls the auth method’s authorize() method.

    Declaration

    Swift

    open func authorize(with properties: SMARTAuthProperties, callback: @escaping ((_ patient: Patient?, _ error: Error?) -> Void))

    Parameters

    properties

    The auth properties to use

    callback

    Callback to call when authorization is complete, providing the chosen patient (if the patient scope was provided) or an error, if any

  • Aborts ongoing authorization and requests session.

    Declaration

    Swift

    open func abort()
  • Runs dynamic client registration unless the client has a client id (or no registration URL is known). Since this happens automatically during authorize() you probably won’t need to call this method explicitly.

    Declaration

    Swift

    open func registerIfNeeded(callback: @escaping ((_ json: OAuth2JSON?, _ error: Error?) -> Void))

    Parameters

    callback

    The callback to call when completed or failed; if both json and error is nil no registration was attempted