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        #[deprecated = "Use initWithURL:callback:completionHandler: instead"]
94        #[unsafe(method(initWithURL:callbackURLScheme:completionHandler:))]
95        #[unsafe(method_family = init)]
96        pub unsafe fn initWithURL_callbackURLScheme_completionHandler(
97            this: Allocated<Self>,
98            url: &NSURL,
99            callback_url_scheme: Option<&NSString>,
100            completion_handler: ASWebAuthenticationSessionCompletionHandler,
101        ) -> Retained<Self>;
102
103        #[cfg(all(feature = "ASWebAuthenticationSessionCallback", feature = "block2"))]
104        #[unsafe(method(initWithURL:callback:completionHandler:))]
105        #[unsafe(method_family = init)]
106        pub unsafe fn initWithURL_callback_completionHandler(
107            this: Allocated<Self>,
108            url: &NSURL,
109            callback: &ASWebAuthenticationSessionCallback,
110            completion_handler: ASWebAuthenticationSessionCompletionHandler,
111        ) -> Retained<Self>;
112
113        /// Provides context to target where in an application's UI the authorization view should be shown. A provider
114        /// must be set prior to calling -start, otherwise the authorization view cannot be displayed. If deploying to iOS prior to
115        /// 13.0, the desired window is inferred by the application's key window.
116        #[unsafe(method(presentationContextProvider))]
117        #[unsafe(method_family = none)]
118        pub unsafe fn presentationContextProvider(
119            &self,
120            mtm: MainThreadMarker,
121        ) -> Option<Retained<ProtocolObject<dyn ASWebAuthenticationPresentationContextProviding>>>;
122
123        /// This is a [weak property][objc2::topics::weak_property].
124        /// Setter for [`presentationContextProvider`][Self::presentationContextProvider].
125        #[unsafe(method(setPresentationContextProvider:))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn setPresentationContextProvider(
128            &self,
129            presentation_context_provider: Option<
130                &ProtocolObject<dyn ASWebAuthenticationPresentationContextProviding>,
131            >,
132        );
133
134        /// Indicates whether this session should ask the browser for an ephemeral session.
135        ///
136        /// Ephemeral web browser sessions do not not share cookies or other browsing data with a user's normal browser session.
137        /// This value is NO by default. Setting this property after calling -[ASWebAuthenticationSession start] has no effect.
138        #[unsafe(method(prefersEphemeralWebBrowserSession))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn prefersEphemeralWebBrowserSession(&self) -> bool;
141
142        /// Setter for [`prefersEphemeralWebBrowserSession`][Self::prefersEphemeralWebBrowserSession].
143        #[unsafe(method(setPrefersEphemeralWebBrowserSession:))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn setPrefersEphemeralWebBrowserSession(
146            &self,
147            prefers_ephemeral_web_browser_session: bool,
148        );
149
150        /// Any additional header fields to be set when loading the initial URL.
151        /// All header field names must start with the "X-" prefix.
152        #[unsafe(method(additionalHeaderFields))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn additionalHeaderFields(
155            &self,
156        ) -> Option<Retained<NSDictionary<NSString, NSString>>>;
157
158        /// Setter for [`additionalHeaderFields`][Self::additionalHeaderFields].
159        #[unsafe(method(setAdditionalHeaderFields:))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn setAdditionalHeaderFields(
162            &self,
163            additional_header_fields: Option<&NSDictionary<NSString, NSString>>,
164        );
165
166        /// Returns whether the session can be successfully started. This property returns the same value as calling -start,
167        /// but without the side effect of actually starting the session.
168        #[unsafe(method(canStart))]
169        #[unsafe(method_family = none)]
170        pub unsafe fn canStart(&self) -> bool;
171
172        /// Starts the ASWebAuthenticationSession instance after it is instantiated.
173        ///
174        /// start can only be called once for an ASWebAuthenticationSession instance. This also means calling start on a
175        /// canceled session will fail.
176        ///
177        /// Returns: Returns YES if the session starts successfully.
178        #[unsafe(method(start))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn start(&self) -> bool;
181
182        /// Cancel an ASWebAuthenticationSession. If the view controller is already presented to load the webpage for
183        /// authentication, it will be dismissed. Calling cancel on an already canceled session will have no effect.
184        #[unsafe(method(cancel))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn cancel(&self);
187
188        #[unsafe(method(new))]
189        #[unsafe(method_family = new)]
190        pub unsafe fn new() -> Retained<Self>;
191
192        #[unsafe(method(init))]
193        #[unsafe(method_family = init)]
194        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
195    );
196}
197
198extern_protocol!(
199    /// Provides context to target where in an application's UI the authorization view should be shown.
200    ///
201    /// See also [Apple's documentation](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationpresentationcontextproviding?language=objc)
202    pub unsafe trait ASWebAuthenticationPresentationContextProviding:
203        NSObjectProtocol + MainThreadOnly
204    {
205        #[cfg(feature = "ASFoundation")]
206        #[cfg(target_os = "macos")]
207        /// Return the ASPresentationAnchor in the closest proximity to where a user interacted with your app to trigger
208        /// authentication. If starting an ASWebAuthenticationSession on first launch, use the application's main window.
209        ///
210        /// Parameter `session`: The session requesting a presentation anchor.
211        ///
212        /// Returns: The ASPresentationAnchor most closely associated with the UI used to trigger authentication.
213        #[unsafe(method(presentationAnchorForWebAuthenticationSession:))]
214        #[unsafe(method_family = none)]
215        unsafe fn presentationAnchorForWebAuthenticationSession(
216            &self,
217            session: &ASWebAuthenticationSession,
218        ) -> Retained<ASPresentationAnchor>;
219    }
220);