objc2-authentication-services 0.3.2

Bindings to the AuthenticationServices framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerdelegate?language=objc)
    pub unsafe trait ASAuthorizationControllerDelegate:
        NSObjectProtocol + MainThreadOnly
    {
        #[cfg(feature = "ASAuthorization")]
        #[optional]
        #[unsafe(method(authorizationController:didCompleteWithAuthorization:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationController_didCompleteWithAuthorization(
            &self,
            controller: &ASAuthorizationController,
            authorization: &ASAuthorization,
        );

        #[optional]
        #[unsafe(method(authorizationController:didCompleteWithError:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationController_didCompleteWithError(
            &self,
            controller: &ASAuthorizationController,
            error: &NSError,
        );

        #[cfg(feature = "ASAuthorizationCustomMethod")]
        #[optional]
        #[unsafe(method(authorizationController:didCompleteWithCustomMethod:))]
        #[unsafe(method_family = none)]
        unsafe fn authorizationController_didCompleteWithCustomMethod(
            &self,
            controller: &ASAuthorizationController,
            method: &ASAuthorizationCustomMethod,
        );
    }
);

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerpresentationcontextproviding?language=objc)
    pub unsafe trait ASAuthorizationControllerPresentationContextProviding:
        NSObjectProtocol + MainThreadOnly
    {
        #[cfg(feature = "ASFoundation")]
        #[cfg(target_os = "macos")]
        /// Return a view anchor that is most appropriate for athorization UI to be presented over.  This view will be used as a hint if a credential provider requires user interaction.
        #[unsafe(method(presentationAnchorForAuthorizationController:))]
        #[unsafe(method_family = none)]
        unsafe fn presentationAnchorForAuthorizationController(
            &self,
            controller: &ASAuthorizationController,
        ) -> Retained<ASPresentationAnchor>;
    }
);

/// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/asauthorizationcontrollerrequestoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ASAuthorizationControllerRequestOptions(pub NSUInteger);
bitflags::bitflags! {
    impl ASAuthorizationControllerRequestOptions: NSUInteger {
/// When used for sign-in requests, tell the authorization controller that it should only be presented if there are credentials immediately available on the local device.
/// When used for registration requests, tell the authorization controller that it should only be presented if the local device is currently set up to fulfill at least one of the request types.
        #[doc(alias = "ASAuthorizationControllerRequestOptionPreferImmediatelyAvailableCredentials")]
        const PreferImmediatelyAvailableCredentials = 1<<0;
    }
}

unsafe impl Encode for ASAuthorizationControllerRequestOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for ASAuthorizationControllerRequestOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/asauthorizationcontroller?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct ASAuthorizationController;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for ASAuthorizationController {}
);

impl ASAuthorizationController {
    extern_methods!(
        #[cfg(feature = "ASAuthorizationRequest")]
        /// Authorization requests that are being serviced by this controller
        #[unsafe(method(authorizationRequests))]
        #[unsafe(method_family = none)]
        pub unsafe fn authorizationRequests(&self) -> Retained<NSArray<ASAuthorizationRequest>>;

        /// This delegate will be invoked upon completion of the authorization indicating success or failure.
        /// Delegate is required to receive the results of authorization.
        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
            mtm: MainThreadMarker,
        ) -> Option<Retained<ProtocolObject<dyn ASAuthorizationControllerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn ASAuthorizationControllerDelegate>>,
        );

        /// This delegate will be invoked upon needing a presentation context to display authorization UI.
        #[unsafe(method(presentationContextProvider))]
        #[unsafe(method_family = none)]
        pub unsafe fn presentationContextProvider(
            &self,
            mtm: MainThreadMarker,
        ) -> Option<
            Retained<ProtocolObject<dyn ASAuthorizationControllerPresentationContextProviding>>,
        >;

        /// Setter for [`presentationContextProvider`][Self::presentationContextProvider].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setPresentationContextProvider:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPresentationContextProvider(
            &self,
            presentation_context_provider: Option<
                &ProtocolObject<dyn ASAuthorizationControllerPresentationContextProviding>,
            >,
        );

        #[cfg(feature = "ASAuthorizationCustomMethod")]
        /// A list of custom authorization methods that may be displayed in the authorization UI.
        ///
        /// If the user selects one of these methods, instead of attempting to secure an authorization for the requests, the
        /// controller will call authorizationController:didCompleteWithCustomMethod: with the selected method, allowing
        /// the client to perform the requested authorization.
        #[unsafe(method(customAuthorizationMethods))]
        #[unsafe(method_family = none)]
        pub unsafe fn customAuthorizationMethods(
            &self,
        ) -> Retained<NSArray<ASAuthorizationCustomMethod>>;

        #[cfg(feature = "ASAuthorizationCustomMethod")]
        /// Setter for [`customAuthorizationMethods`][Self::customAuthorizationMethods].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCustomAuthorizationMethods:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCustomAuthorizationMethods(
            &self,
            custom_authorization_methods: &NSArray<ASAuthorizationCustomMethod>,
        );

        #[cfg(feature = "ASAuthorizationRequest")]
        /// Initialize the controller with authorization requests.
        ///
        ///
        /// Parameter `authorizationRequests`: At least one request should be provided. Requests of same type maybe honored in first in first out order
        #[unsafe(method(initWithAuthorizationRequests:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithAuthorizationRequests(
            this: Allocated<Self>,
            authorization_requests: &NSArray<ASAuthorizationRequest>,
        ) -> Retained<Self>;

        /// Initiate the authorization flows. Upon completion, the delegate will be called with either success or failure.
        /// Certain authorization flows may require a presentation context. The
        /// `presentationContextProvider`will be called
        /// to provide it.
        ///
        /// The instance will remain retained until the flow is either completed or canceled, and the delegate callback is made.
        #[unsafe(method(performRequests))]
        #[unsafe(method_family = none)]
        pub unsafe fn performRequests(&self);

        /// Initiate the authorization flows for requests that support AutoFill presentation. UI will be shown when
        /// focusing a text field with the appropriate text content type. Upon completion, the delegate will be called with either success
        /// or failure.
        ///
        /// The instance will remain retained until the flow is either completed or canceled, and the delegate callback is made.
        #[unsafe(method(performAutoFillAssistedRequests))]
        #[unsafe(method_family = none)]
        pub unsafe fn performAutoFillAssistedRequests(&self);

        /// Initiate the authorization flows. Upon completion, the delegate will be called with either success or failure.
        /// Certain authorization flows may require a presentation context. The
        /// `presentationContextProvider`will be called
        /// to provide it.
        ///
        /// Calling this method with no options is the same as calling
        /// `performRequests.`The instance will remain retained until
        /// the flow is either completed or canceled, and the delegate callback is made.
        #[unsafe(method(performRequestsWithOptions:))]
        #[unsafe(method_family = none)]
        pub unsafe fn performRequestsWithOptions(
            &self,
            options: ASAuthorizationControllerRequestOptions,
        );

        /// Cancel the running authorization flows, if there are any. If a flow is canceled, the delegate callback will
        /// be made indicating the cancel.
        #[unsafe(method(cancel))]
        #[unsafe(method_family = none)]
        pub unsafe fn cancel(&self);

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
    );
}