Pass a hint from the extension to decidePolicyForSOAuthorizationLoadWithCurrentPolicy
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / cocoa / AppSSOSPI.h
1 /*
2  * Copyright (C) 2019 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #if HAVE(APP_SSO)
29
30 #if USE(APPLE_INTERNAL_SDK)
31
32 #import <AppSSO/AppSSO.h>
33 #import <AppSSOCore/AppSSOCore.h>
34
35 #else
36
37 #if __has_include(<UIKit/UIKit.h>)
38 #import <UIKit/UIKit.h>
39 typedef UIViewController * SOAuthorizationViewController;
40 #elif __has_include(<AppKit/AppKit.h>)
41 typedef id SOAuthorizationViewController;
42 #endif
43
44 NS_ASSUME_NONNULL_BEGIN
45
46 #define kSOErrorAuthorizationPresentationFailed -7
47
48 extern NSErrorDomain const SOErrorDomain;
49
50 typedef NSString * SOAuthorizationOperation;
51
52 @class SOAuthorization;
53 @class SOAuthorizationParameters;
54
55 @protocol SOAuthorizationDelegate <NSObject>
56 @optional
57 - (void)authorizationDidNotHandle:(SOAuthorization *)authorization;
58 - (void)authorizationDidCancel:(SOAuthorization *)authorization;
59 - (void)authorizationDidComplete:(SOAuthorization *)authorization;
60 - (void)authorization:(SOAuthorization *)authorization didCompleteWithHTTPAuthorizationHeaders:(NSDictionary<NSString *, NSString *> *)httpAuthorizationHeaders;
61 - (void)authorization:(SOAuthorization *)authorization didCompleteWithHTTPResponse:(NSHTTPURLResponse *)httpResponse httpBody:(NSData *)httpBody;
62 - (void)authorization:(SOAuthorization *)authorization didCompleteWithError:(NSError *)error;
63 - (void)authorization:(SOAuthorization *)authorization presentViewController:(SOAuthorizationViewController)viewController withCompletion:(void (^)(BOOL success, NSError * _Nullable error))completion;
64 @end
65
66 typedef NSString * SOAuthorizationOption;
67 extern SOAuthorizationOption const SOAuthorizationOptionUserActionInitiated;
68 extern SOAuthorizationOption const SOAuthorizationOptionInitiatorOrigin;
69 extern SOAuthorizationOption const SOAuthorizationOptionInitiatingAction;
70
71 typedef NS_ENUM(NSInteger, SOAuthorizationInitiatingAction) {
72     SOAuthorizationInitiatingActionRedirect,
73     SOAuthorizationInitiatingActionPopUp,
74     SOAuthorizationInitiatingActionKerberos,
75     SOAuthorizationInitiatingActionSubframe,
76 };
77
78 @interface SOAuthorizationHintsCore : NSObject <NSSecureCoding>
79
80 - (instancetype)initWithLocalizedExtensionBundleDisplayName:(NSString *)localizedExtensionBundleDisplayName;
81
82 @property (nonatomic, readonly) NSString *localizedExtensionBundleDisplayName;
83
84 @end
85
86 @interface SOAuthorizationHints : NSObject
87
88 - (instancetype)initWithAuthorizationHintsCore:(SOAuthorizationHintsCore *)authorizationHintsCore;
89
90 @property (nonatomic, readonly) NSString *localizedExtensionBundleDisplayName;
91
92 @end
93
94 @interface SOAuthorization : NSObject
95 @property (weak) id<SOAuthorizationDelegate> delegate;
96 @property (retain, nullable) dispatch_queue_t delegateDispatchQueue;
97 @property (copy, nonatomic) NSDictionary *authorizationOptions;
98 @property (nonatomic) BOOL enableEmbeddedAuthorizationViewController;
99 - (void)getAuthorizationHintsWithURL:(NSURL *)url responseCode:(NSInteger)responseCode completion:(void (^)(SOAuthorizationHints * _Nullable authorizationHints, NSError * _Nullable error))completion;
100 + (BOOL)canPerformAuthorizationWithURL:(NSURL *)url responseCode:(NSInteger)responseCode;
101 + (BOOL)canPerformAuthorizationWithURL:(NSURL *)url responseCode:(NSInteger)responseCode useInternalExtensions:(BOOL)useInternalExtensions;
102 - (void)beginAuthorizationWithURL:(NSURL *)url httpHeaders:(NSDictionary <NSString *, NSString *> *)httpHeaders httpBody:(NSData *)httpBody;
103 - (void)beginAuthorizationWithOperation:(nullable SOAuthorizationOperation)operation url:(NSURL *)url httpHeaders:(NSDictionary <NSString *, NSString *> *)httpHeaders httpBody:(NSData *)httpBody;
104 - (void)beginAuthorizationWithParameters:(SOAuthorizationParameters *)parameters;
105 - (void)cancelAuthorization;
106 @end
107
108 NS_ASSUME_NONNULL_END
109
110 #endif // USE(APPLE_INTERNAL_SDK)
111
112 #endif // HAVE(APP_SSO)