objc2_authentication_services/generated/
ASWebAuthenticationSession.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern "C" {
11    /// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsessionerrordomain?language=objc)
12    pub static ASWebAuthenticationSessionErrorDomain: &'static NSErrorDomain;
13}
14
15/// Error code of the NSError object passed in by ASWebAuthenticationSessionCompletionHandler.
16///
17/// alert asking for permission to log in to this app, or by dismissing the view controller for loading the
18/// authentication webpage.
19///
20/// was not found when -start was called. Ensure this property was not nil when -start was called.
21///
22/// was not elligible to show the authentication UI. For iOS, validate that the UIWindow is in a foreground scene.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsessionerrorcode?language=objc)
25// NS_ERROR_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct ASWebAuthenticationSessionErrorCode(pub NSInteger);
29impl ASWebAuthenticationSessionErrorCode {
30    #[doc(alias = "ASWebAuthenticationSessionErrorCodeCanceledLogin")]
31    pub const CanceledLogin: Self = Self(1);
32    #[doc(alias = "ASWebAuthenticationSessionErrorCodePresentationContextNotProvided")]
33    pub const PresentationContextNotProvided: Self = Self(2);
34    #[doc(alias = "ASWebAuthenticationSessionErrorCodePresentationContextInvalid")]
35    pub const PresentationContextInvalid: Self = Self(3);
36}
37
38unsafe impl Encode for ASWebAuthenticationSessionErrorCode {
39    const ENCODING: Encoding = NSInteger::ENCODING;
40}
41
42unsafe impl RefEncode for ASWebAuthenticationSessionErrorCode {
43    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46/// [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsessioncompletionhandler?language=objc)
47#[cfg(feature = "block2")]
48pub type ASWebAuthenticationSessionCompletionHandler =
49    *mut block2::DynBlock<dyn Fn(*mut NSURL, *mut NSError)>;
50
51extern_class!(
52    /// An ASWebAuthenticationSession object can be used to authenticate a user with a web service, even if the web service is run
53    /// by a third party. ASWebAuthenticationSession puts the user in control of whether they want to use their existing logged-in
54    /// session from Safari. The app provides a URL that points to the authentication webpage. The page will be loaded in a secure
55    /// view controller. From the webpage, the user can authenticate herself and grant access to the app.
56    /// On completion, the service will send a callback URL with an authentication token, and this URL will be passed to the app by
57    /// ASWebAuthenticationSessionCompletionHandler.
58    ///
59    /// The callback URL usually has a custom URL scheme. For the app to receive the callback URL, it needs to either register the
60    /// custom URL scheme in its Info.plist, or set the scheme to callbackURLScheme argument in the initializer.
61    ///
62    /// If the user has already logged into the web service in Safari or other apps via ASWebAuthenticationSession, it is possible to
63    /// share the existing login information. An alert will be presented to get the user's consent for sharing their existing login
64    /// information. If the user cancels the alert, the session will be canceled, and the completion handler will be called with
65    /// the error code ASWebAuthenticationSessionErrorCodeCanceledLogin.
66    ///
67    /// If the user taps Cancel when showing the login webpage for the web service, the session will be canceled, and the completion
68    /// handler will be called with the error code ASWebAuthenticationSessionErrorCodeCanceledLogin.
69    ///
70    /// The app can cancel the session by calling -[ASWebAuthenticationSession cancel]. This will also dismiss the view controller that
71    /// is showing the web service's login page.
72    ///
73    /// See also [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession?language=objc)
74    #[unsafe(super(NSObject))]
75    #[derive(Debug, PartialEq, Eq, Hash)]
76    pub struct ASWebAuthenticationSession;
77);
78
79extern_conformance!(
80    unsafe impl NSObjectProtocol for ASWebAuthenticationSession {}
81);
82
83impl ASWebAuthenticationSession {
84    extern_methods!(
85        #[cfg(feature = "block2")]
86        /// Returns an ASWebAuthenticationSession object.
87        ///
88        /// Parameter `URL`: the initial URL pointing to the authentication webpage. Only supports URLs with http:// or https:// schemes.
89        ///
90        /// Parameter `callbackURLScheme`: the custom URL scheme that the app expects in the callback URL.
91        ///
92        /// Parameter `completionHandler`: the completion handler which is called when the session is completed successfully or canceled by user.
93        ///
94        /// # Safety
95        ///
96        /// `completion_handler` must be a valid pointer.
97        #[deprecated = "Use initWithURL:callback:completionHandler: instead"]
98        #[unsafe(method(initWithURL:callbackURLScheme:completionHandler:))]
99        #[unsafe(method_family = init)]
100        pub unsafe fn initWithURL_callbackURLScheme_completionHandler(
101            this: Allocated<Self>,
102            url: &NSURL,
103            callback_url_scheme: Option<&NSString>,
104            completion_handler: ASWebAuthenticationSessionCompletionHandler,
105        ) -> Retained<Self>;
106
107        #[cfg(all(feature = "ASWebAuthenticationSessionCallback", feature = "block2"))]
108        /// # Safety
109        ///
110        /// `completion_handler` must be a valid pointer.
111        #[unsafe(method(initWithURL:callback:completionHandler:))]
112        #[unsafe(method_family = init)]
113        pub unsafe fn initWithURL_callback_completionHandler(
114            this: Allocated<Self>,
115            url: &NSURL,
116            callback: &ASWebAuthenticationSessionCallback,
117            completion_handler: ASWebAuthenticationSessionCompletionHandler,
118        ) -> Retained<Self>;
119
120        /// Provides context to target where in an application's UI the authorization view should be shown. A provider
121        /// must be set prior to calling -start, otherwise the authorization view cannot be displayed. If deploying to iOS prior to
122        /// 13.0, the desired window is inferred by the application's key window.
123        #[unsafe(method(presentationContextProvider))]
124        #[unsafe(method_family = none)]
125        pub unsafe fn presentationContextProvider(
126            &self,
127            mtm: MainThreadMarker,
128        ) -> Option<Retained<ProtocolObject<dyn ASWebAuthenticationPresentationContextProviding>>>;
129
130        /// Setter for [`presentationContextProvider`][Self::presentationContextProvider].
131        ///
132        /// This is a [weak property][objc2::topics::weak_property].
133        #[unsafe(method(setPresentationContextProvider:))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn setPresentationContextProvider(
136            &self,
137            presentation_context_provider: Option<
138                &ProtocolObject<dyn ASWebAuthenticationPresentationContextProviding>,
139            >,
140        );
141
142        /// Indicates whether this session should ask the browser for an ephemeral session.
143        ///
144        /// Ephemeral web browser sessions do not not share cookies or other browsing data with a user's normal browser session.
145        /// This value is NO by default. Setting this property after calling -[ASWebAuthenticationSession start] has no effect.
146        #[unsafe(method(prefersEphemeralWebBrowserSession))]
147        #[unsafe(method_family = none)]
148        pub unsafe fn prefersEphemeralWebBrowserSession(&self) -> bool;
149
150        /// Setter for [`prefersEphemeralWebBrowserSession`][Self::prefersEphemeralWebBrowserSession].
151        #[unsafe(method(setPrefersEphemeralWebBrowserSession:))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn setPrefersEphemeralWebBrowserSession(
154            &self,
155            prefers_ephemeral_web_browser_session: bool,
156        );
157
158        /// Any additional header fields to be set when loading the initial URL.
159        /// All header field names must start with the "X-" prefix.
160        #[unsafe(method(additionalHeaderFields))]
161        #[unsafe(method_family = none)]
162        pub unsafe fn additionalHeaderFields(
163            &self,
164        ) -> Option<Retained<NSDictionary<NSString, NSString>>>;
165
166        /// Setter for [`additionalHeaderFields`][Self::additionalHeaderFields].
167        #[unsafe(method(setAdditionalHeaderFields:))]
168        #[unsafe(method_family = none)]
169        pub unsafe fn setAdditionalHeaderFields(
170            &self,
171            additional_header_fields: Option<&NSDictionary<NSString, NSString>>,
172        );
173
174        /// Returns whether the session can be successfully started. This property returns the same value as calling -start,
175        /// but without the side effect of actually starting the session.
176        #[unsafe(method(canStart))]
177        #[unsafe(method_family = none)]
178        pub unsafe fn canStart(&self) -> bool;
179
180        /// Starts the ASWebAuthenticationSession instance after it is instantiated.
181        ///
182        /// start can only be called once for an ASWebAuthenticationSession instance. This also means calling start on a
183        /// canceled session will fail.
184        ///
185        /// Returns: Returns YES if the session starts successfully.
186        #[unsafe(method(start))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn start(&self) -> bool;
189
190        /// Cancel an ASWebAuthenticationSession. If the view controller is already presented to load the webpage for
191        /// authentication, it will be dismissed. Calling cancel on an already canceled session will have no effect.
192        #[unsafe(method(cancel))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn cancel(&self);
195
196        #[unsafe(method(new))]
197        #[unsafe(method_family = new)]
198        pub unsafe fn new() -> Retained<Self>;
199
200        #[unsafe(method(init))]
201        #[unsafe(method_family = init)]
202        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
203    );
204}
205
206extern_protocol!(
207    /// Provides context to target where in an application's UI the authorization view should be shown.
208    ///
209    /// See also [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationpresentationcontextproviding?language=objc)
210    pub unsafe trait ASWebAuthenticationPresentationContextProviding:
211        NSObjectProtocol + MainThreadOnly
212    {
213        #[cfg(feature = "ASFoundation")]
214        #[cfg(target_os = "macos")]
215        /// Return the ASPresentationAnchor in the closest proximity to where a user interacted with your app to trigger
216        /// authentication. If starting an ASWebAuthenticationSession on first launch, use the application's main window.
217        ///
218        /// Parameter `session`: The session requesting a presentation anchor.
219        ///
220        /// Returns: The ASPresentationAnchor most closely associated with the UI used to trigger authentication.
221        #[unsafe(method(presentationAnchorForWebAuthenticationSession:))]
222        #[unsafe(method_family = none)]
223        unsafe fn presentationAnchorForWebAuthenticationSession(
224            &self,
225            session: &ASWebAuthenticationSession,
226        ) -> Retained<ASPresentationAnchor>;
227    }
228);