Skip to content

Commit

Permalink
Add support for the AuthenticationServices framework
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 24, 2022
1 parent e581197 commit d18a2f4
Show file tree
Hide file tree
Showing 68 changed files with 2,641 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crates/header-translator/framework-includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#endif

#import <AuthenticationServices/AuthenticationServices.h>
3 changes: 3 additions & 0 deletions crates/header-translator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub struct Config {
pub struct ClassData {
#[serde(default)]
pub skipped: bool,
#[serde(rename = "superclass-name")]
#[serde(default)]
pub new_superclass_name: Option<String>,
#[serde(default)]
pub methods: HashMap<String, MethodData>,
#[serde(default)]
Expand Down
14 changes: 10 additions & 4 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ fn parse_objc_decl(
methods.push(MethodOrProperty::Property(property));
}
}
EntityKind::VisibilityAttr if superclass.is_some() => {
// NS_CLASS_AVAILABLE_MAC??
println!("TODO: VisibilityAttr")
EntityKind::VisibilityAttr => {
// Already exposed as entity.get_visibility()
}
EntityKind::TypeRef if superclass.is_some() => {
// TODO
Expand Down Expand Up @@ -312,6 +311,12 @@ impl Stmt {
class_data,
);

if let Some(new_name) =
class_data.and_then(|data| data.new_superclass_name.as_ref())
{
superclass = Some(Some(new_name.clone()));
}

let superclass = superclass.expect("no superclass found");

Some(Self::ClassDecl {
Expand Down Expand Up @@ -579,6 +584,7 @@ impl Stmt {
panic!("unexpected attribute: {macro_:?}");
}
}
EntityKind::VisibilityAttr => {}
EntityKind::ObjCClassRef => {}
EntityKind::TypeRef => {}
_ if entity.is_expression() => {
Expand All @@ -588,7 +594,7 @@ impl Stmt {
panic!("got variable value twice")
}
}
_ => panic!("unknown typedef child in {name}: {entity:?}"),
_ => panic!("unknown vardecl child in {name}: {entity:?}"),
};
EntityVisitResult::Continue
});
Expand Down
2 changes: 1 addition & 1 deletion crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ AppKit = ["Foundation", "CoreData"]
# AudioUnit = []
# AudioDriverKit = []
# AudioVideoBridging = []
# AuthenticationServices = []
AuthenticationServices = ["Foundation"]
# AutomaticAssessmentConfiguration = []
# Automator = []
# AVFAudio = []
Expand Down
11 changes: 11 additions & 0 deletions crates/icrate/src/AuthenticationServices/fixes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::Foundation::NSObject;

// TODO: UIViewController on iOS, NSViewController on macOS
pub type ASViewController = NSObject;
// TODO: UIWindow on iOS, NSWindow on macOS
pub type ASPresentationAnchor = NSObject;
// TODO: UIImage on iOS, NSImage on macOS
pub type ASImage = NSObject;

// TODO: UIControl on iOS, NSControl on macOS
pub(crate) type ASControl = NSObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_protocol!(
pub struct ASAccountAuthenticationModificationControllerDelegate;

unsafe impl ASAccountAuthenticationModificationControllerDelegate {
#[optional]
#[method(accountAuthenticationModificationController:didSuccessfullyCompleteRequest:withUserInfo:)]
pub unsafe fn accountAuthenticationModificationController_didSuccessfullyCompleteRequest_withUserInfo(
&self,
controller: &ASAccountAuthenticationModificationController,
request: &ASAccountAuthenticationModificationRequest,
userInfo: Option<&NSDictionary>,
);

#[optional]
#[method(accountAuthenticationModificationController:didFailRequest:withError:)]
pub unsafe fn accountAuthenticationModificationController_didFailRequest_withError(
&self,
controller: &ASAccountAuthenticationModificationController,
request: &ASAccountAuthenticationModificationRequest,
error: &NSError,
);
}
);

extern_protocol!(
pub struct ASAccountAuthenticationModificationControllerPresentationContextProviding;

unsafe impl ASAccountAuthenticationModificationControllerPresentationContextProviding {
#[method_id(@__retain_semantics Other presentationAnchorForAccountAuthenticationModificationController:)]
pub unsafe fn presentationAnchorForAccountAuthenticationModificationController(
&self,
controller: &ASAccountAuthenticationModificationController,
) -> Id<ASPresentationAnchor, Shared>;
}
);

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationController;

unsafe impl ClassType for ASAccountAuthenticationModificationController {
type Super = NSObject;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationController {
#[method_id(@__retain_semantics Other delegate)]
pub unsafe fn delegate(
&self,
) -> Option<Id<ASAccountAuthenticationModificationControllerDelegate, Shared>>;

#[method(setDelegate:)]
pub unsafe fn setDelegate(
&self,
delegate: Option<&ASAccountAuthenticationModificationControllerDelegate>,
);

#[method_id(@__retain_semantics Other presentationContextProvider)]
pub unsafe fn presentationContextProvider(
&self,
) -> Option<
Id<ASAccountAuthenticationModificationControllerPresentationContextProviding, Shared>,
>;

#[method(setPresentationContextProvider:)]
pub unsafe fn setPresentationContextProvider(
&self,
presentationContextProvider: Option<
&ASAccountAuthenticationModificationControllerPresentationContextProviding,
>,
);

#[method(performRequest:)]
pub unsafe fn performRequest(&self, request: &ASAccountAuthenticationModificationRequest);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationExtensionContext;

unsafe impl ClassType for ASAccountAuthenticationModificationExtensionContext {
type Super = NSExtensionContext;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationExtensionContext {
#[method(getSignInWithAppleUpgradeAuthorizationWithState:nonce:completionHandler:)]
pub unsafe fn getSignInWithAppleUpgradeAuthorizationWithState_nonce_completionHandler(
&self,
state: Option<&NSString>,
nonce: Option<&NSString>,
completionHandler: &Block<(*mut ASAuthorizationAppleIDCredential, *mut NSError), ()>,
);

#[method(completeUpgradeToSignInWithAppleWithUserInfo:)]
pub unsafe fn completeUpgradeToSignInWithAppleWithUserInfo(
&self,
userInfo: Option<&NSDictionary>,
);

#[method(completeChangePasswordRequestWithUpdatedCredential:userInfo:)]
pub unsafe fn completeChangePasswordRequestWithUpdatedCredential_userInfo(
&self,
updatedCredential: &ASPasswordCredential,
userInfo: Option<&NSDictionary>,
);

#[method(cancelRequestWithError:)]
pub unsafe fn cancelRequestWithError(&self, error: &NSError);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationReplacePasswordWithSignInWithAppleRequest;

unsafe impl ClassType
for ASAccountAuthenticationModificationReplacePasswordWithSignInWithAppleRequest
{
type Super = ASAccountAuthenticationModificationRequest;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationReplacePasswordWithSignInWithAppleRequest {
#[method_id(@__retain_semantics Init initWithUser:serviceIdentifier:userInfo:)]
pub unsafe fn initWithUser_serviceIdentifier_userInfo(
this: Option<Allocated<Self>>,
user: &NSString,
serviceIdentifier: &ASCredentialServiceIdentifier,
userInfo: Option<&NSDictionary>,
) -> Id<Self, Shared>;

#[method_id(@__retain_semantics Other user)]
pub unsafe fn user(&self) -> Id<NSString, Shared>;

#[method_id(@__retain_semantics Other serviceIdentifier)]
pub unsafe fn serviceIdentifier(&self) -> Id<ASCredentialServiceIdentifier, Shared>;

#[method_id(@__retain_semantics Other userInfo)]
pub unsafe fn userInfo(&self) -> Option<Id<NSDictionary, Shared>>;
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationRequest;

unsafe impl ClassType for ASAccountAuthenticationModificationRequest {
type Super = NSObject;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationRequest {}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationUpgradePasswordToStrongPasswordRequest;

unsafe impl ClassType
for ASAccountAuthenticationModificationUpgradePasswordToStrongPasswordRequest
{
type Super = ASAccountAuthenticationModificationRequest;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationUpgradePasswordToStrongPasswordRequest {
#[method_id(@__retain_semantics Init initWithUser:serviceIdentifier:userInfo:)]
pub unsafe fn initWithUser_serviceIdentifier_userInfo(
this: Option<Allocated<Self>>,
user: &NSString,
serviceIdentifier: &ASCredentialServiceIdentifier,
userInfo: Option<&NSDictionary>,
) -> Id<Self, Shared>;

#[method_id(@__retain_semantics Other user)]
pub unsafe fn user(&self) -> Id<NSString, Shared>;

#[method_id(@__retain_semantics Other serviceIdentifier)]
pub unsafe fn serviceIdentifier(&self) -> Id<ASCredentialServiceIdentifier, Shared>;

#[method_id(@__retain_semantics Other userInfo)]
pub unsafe fn userInfo(&self) -> Option<Id<NSDictionary, Shared>>;
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

extern_class!(
#[derive(Debug)]
pub struct ASAccountAuthenticationModificationViewController;

unsafe impl ClassType for ASAccountAuthenticationModificationViewController {
type Super = ASViewController;
}
);

extern_methods!(
unsafe impl ASAccountAuthenticationModificationViewController {
#[method_id(@__retain_semantics Other extensionContext)]
pub unsafe fn extensionContext(
&self,
) -> Id<ASAccountAuthenticationModificationExtensionContext, Shared>;

#[method(convertAccountToSignInWithAppleWithoutUserInteractionForServiceIdentifier:existingCredential:userInfo:)]
pub unsafe fn convertAccountToSignInWithAppleWithoutUserInteractionForServiceIdentifier_existingCredential_userInfo(
&self,
serviceIdentifier: &ASCredentialServiceIdentifier,
existingCredential: &ASPasswordCredential,
userInfo: Option<&NSDictionary>,
);

#[method(prepareInterfaceToConvertAccountToSignInWithAppleForServiceIdentifier:existingCredential:userInfo:)]
pub unsafe fn prepareInterfaceToConvertAccountToSignInWithAppleForServiceIdentifier_existingCredential_userInfo(
&self,
serviceIdentifier: &ASCredentialServiceIdentifier,
existingCredential: &ASPasswordCredential,
userInfo: Option<&NSDictionary>,
);

#[method(changePasswordWithoutUserInteractionForServiceIdentifier:existingCredential:newPassword:userInfo:)]
pub unsafe fn changePasswordWithoutUserInteractionForServiceIdentifier_existingCredential_newPassword_userInfo(
&self,
serviceIdentifier: &ASCredentialServiceIdentifier,
existingCredential: &ASPasswordCredential,
newPassword: &NSString,
userInfo: Option<&NSDictionary>,
);

#[method(prepareInterfaceToChangePasswordForServiceIdentifier:existingCredential:newPassword:userInfo:)]
pub unsafe fn prepareInterfaceToChangePasswordForServiceIdentifier_existingCredential_newPassword_userInfo(
&self,
serviceIdentifier: &ASCredentialServiceIdentifier,
existingCredential: &ASPasswordCredential,
newPassword: &NSString,
userInfo: Option<&NSDictionary>,
);

#[method(cancelRequest)]
pub unsafe fn cancelRequest(&self);
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use crate::common::*;
use crate::AuthenticationServices::*;
use crate::Foundation::*;

pub type ASAuthorizationScope = NSString;

extern_static!(ASAuthorizationScopeFullName: &'static ASAuthorizationScope);

extern_static!(ASAuthorizationScopeEmail: &'static ASAuthorizationScope);

extern_class!(
#[derive(Debug)]
pub struct ASAuthorization;

unsafe impl ClassType for ASAuthorization {
type Super = NSObject;
}
);

extern_methods!(
unsafe impl ASAuthorization {
#[method_id(@__retain_semantics Other provider)]
pub unsafe fn provider(&self) -> Id<ASAuthorizationProvider, Shared>;

#[method_id(@__retain_semantics Other credential)]
pub unsafe fn credential(&self) -> Id<ASAuthorizationCredential, Shared>;

#[method_id(@__retain_semantics New new)]
pub unsafe fn new() -> Id<Self, Shared>;

#[method_id(@__retain_semantics Init init)]
pub unsafe fn init(this: Option<Allocated<Self>>) -> Id<Self, Shared>;
}
);
Loading

0 comments on commit d18a2f4

Please sign in to comment.