cpp_quote("#include <winapifamily.h>")

#pragma region Desktop Family
cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)")

import "wtypes.idl";
import "shobjidl.idl";
import "unknwn.idl";

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_USAGE_SCENARIO
{
    CPUS_INVALID = 0,
    CPUS_LOGON,
    CPUS_UNLOCK_WORKSTATION,
    CPUS_CHANGE_PASSWORD,
    CPUS_CREDUI,
    CPUS_PLAP,
} CREDENTIAL_PROVIDER_USAGE_SCENARIO;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_TYPE
{
    CPFT_INVALID = 0,
    CPFT_LARGE_TEXT,
    CPFT_SMALL_TEXT,
    CPFT_COMMAND_LINK,
    CPFT_EDIT_TEXT,
    CPFT_PASSWORD_TEXT,
    CPFT_TILE_IMAGE,
    CPFT_CHECKBOX,
    CPFT_COMBOBOX,
    CPFT_SUBMIT_BUTTON,
} CREDENTIAL_PROVIDER_FIELD_TYPE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_STATE
{
    CPFS_HIDDEN = 0,
    CPFS_DISPLAY_IN_SELECTED_TILE,
    CPFS_DISPLAY_IN_DESELECTED_TILE,
    CPFS_DISPLAY_IN_BOTH,
} CREDENTIAL_PROVIDER_FIELD_STATE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE
{
    CPFIS_NONE = 0,
    CPFIS_READONLY,
    CPFIS_DISABLED,
    CPFIS_FOCUSED,
} CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE;

//
// Note: values for guidFieldType used by Microsoft implementations of ICredentialProvider
//       can be found in shlguid.h.
//
typedef struct _CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR
{
    DWORD dwFieldID;
    CREDENTIAL_PROVIDER_FIELD_TYPE cpft;
    LPWSTR pszLabel;
    GUID guidFieldType;
} CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE
{
    CPGSR_NO_CREDENTIAL_NOT_FINISHED,
    CPGSR_NO_CREDENTIAL_FINISHED,
    CPGSR_RETURN_CREDENTIAL_FINISHED,
    CPGSR_RETURN_NO_CREDENTIAL_FINISHED,
} CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_STATUS_ICON
{
    CPSI_NONE = 0,
    CPSI_ERROR,
    CPSI_WARNING,
    CPSI_SUCCESS,
} CREDENTIAL_PROVIDER_STATUS_ICON;

typedef struct _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION
{
    ULONG   ulAuthenticationPackage;
    GUID    clsidCredentialProvider;
    ULONG   cbSerialization;
    [size_is(cbSerialization)] byte* rgbSerialization;
} CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION;

cpp_quote("#if (NTDDI_VERSION >= NTDDI_WIN8)")
[v1_enum] typedef enum CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS
{
    CPAO_NONE               = 0x00000000,  // Default
    CPAO_EMPTY_LOCAL        = 0x00000001,  // Need to enumerate the local empty tile
    CPAO_EMPTY_CONNECTED    = 0x00000002,  // Need to enumerate the connected empty tile
} CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS;
cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS)")

[v1_enum] typedef enum CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS
{
    CPCFO_NONE                                = 0x00000000,  // Default
    CPCFO_ENABLE_PASSWORD_REVEAL              = 0x00000001,  // Enable the "password reveal" button in the modern control
    CPCFO_IS_EMAIL_ADDRESS                    = 0x00000002,  // This is a email address, so set the keyboard input scope appropriately
    CPCFO_ENABLE_TOUCH_KEYBOARD_AUTO_INVOKE   = 0x00000004,  // Touch keyboard will be invoked automatically on the provider. This should be only set on the CPFG_CREDENTIAL_PROVIDER_LOGO field
    CPCFO_NUMBERS_ONLY                        = 0x00000008,  // The edit field will show numbers only. This should be only set on the CPFT_PASSWORD_TEXT field
} CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS;
cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS)") 
cpp_quote("#endif // (NTDDI_VERSION >= NTDDI_WIN8)")

//
// No idl files contain NTSTATUS.  Therefore we mirror its definition in ntdef.h.
//
#ifndef NTSTATUS
typedef LONG NTSTATUS;
#endif

cpp_quote("#define CREDENTIAL_PROVIDER_NO_DEFAULT       ((DWORD)-1)")

interface ICredentialProviderCredentialEvents; // forward

[
    local,
    object,
    pointer_default(ref),
    uuid(63913a93-40c1-481a-818d-4072ff8c70cc),
]
interface ICredentialProviderCredential : IUnknown
{
    HRESULT Advise([in, annotation("_In_")] ICredentialProviderCredentialEvents* pcpce);
    HRESULT UnAdvise();

    HRESULT SetSelected([out, annotation("_Out_")] BOOL* pbAutoLogon);
    HRESULT SetDeselected();

    HRESULT GetFieldState([in] DWORD dwFieldID,
                          [out, annotation("_Out_")] CREDENTIAL_PROVIDER_FIELD_STATE* pcpfs,
                          [out, annotation("_Out_")] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE* pcpfis);

    HRESULT GetStringValue([in] DWORD dwFieldID, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppsz);
    HRESULT GetBitmapValue([in] DWORD dwFieldID, [out, annotation("_Outptr_result_nullonfailure_")] HBITMAP* phbmp);
    HRESULT GetCheckboxValue([in] DWORD dwFieldID, [out, annotation("_Out_")] BOOL* pbChecked, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppszLabel);
    HRESULT GetSubmitButtonValue([in] DWORD dwFieldID, [out, annotation("_Out_")] DWORD* pdwAdjacentTo);

    HRESULT GetComboBoxValueCount([in] DWORD dwFieldID, [out, annotation("_Out_")] DWORD* pcItems, [out, annotation("_Out_")] DWORD* pdwSelectedItem);
    HRESULT GetComboBoxValueAt([in] DWORD dwFieldID, DWORD dwItem, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppszItem);

    HRESULT SetStringValue([in] DWORD dwFieldID, [in, string, annotation("_In_")] LPCWSTR psz);
    HRESULT SetCheckboxValue([in] DWORD dwFieldID, [in] BOOL bChecked);
    HRESULT SetComboBoxSelectedValue([in] DWORD dwFieldID, [in] DWORD dwSelectedItem);
    HRESULT CommandLinkClicked([in] DWORD dwFieldID);

    HRESULT GetSerialization([out, annotation("_Out_")] CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE* pcpgsr,
                             [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs,
                             [out, annotation("_Outptr_result_maybenull_")] LPWSTR* ppszOptionalStatusText,
                             [out, annotation("_Out_")] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon);
    HRESULT ReportResult([in] NTSTATUS ntsStatus,
                         [in] NTSTATUS ntsSubstatus,
                         [out, annotation("_Outptr_result_maybenull_")] LPWSTR* ppszOptionalStatusText,
                         [out, annotation("_Out_")] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(9090be5b-502b-41fb-bccc-0049a6c7254b),
]
interface IQueryContinueWithStatus : IQueryContinue
{
    HRESULT SetStatusMessage([in, string, annotation("_In_")] LPCWSTR psz);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(9387928b-ac75-4bf9-8ab2-2b93c4a55290),
]
interface IConnectableCredentialProviderCredential : ICredentialProviderCredential
{
    HRESULT Connect([in, annotation("_In_")] IQueryContinueWithStatus* pqcws);
    HRESULT Disconnect();
};

[
    object,
    pointer_default(ref),
    uuid(fa6fa76b-66b7-4b11-95f1-86171118e816),
]
interface ICredentialProviderCredentialEvents : IUnknown
{
    // ICredentialProviderCredential *pcpc parameters on all methods are deprecated, should pass nullptr.
    HRESULT SetFieldState([in] ICredentialProviderCredential* pcpc,
                          [in] DWORD dwFieldID,
                          [in] CREDENTIAL_PROVIDER_FIELD_STATE cpfs);
    HRESULT SetFieldInteractiveState([in] ICredentialProviderCredential* pcpc,
                                     [in] DWORD dwFieldID,
                                     [in] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE cpfis);

    HRESULT SetFieldString([in] ICredentialProviderCredential* pcpc,
                           [in] DWORD dwFieldID,
                           [in, string, unique] LPCWSTR psz);
    HRESULT SetFieldCheckbox([in] ICredentialProviderCredential* pcpc,
                             [in] DWORD dwFieldID,
                             [in] BOOL bChecked,
                             [in] LPCWSTR pszLabel);
    HRESULT SetFieldBitmap([in] ICredentialProviderCredential* pcpc,
                           [in] DWORD dwFieldID,
                           [in] HBITMAP hbmp);

    HRESULT SetFieldComboBoxSelectedItem([in] ICredentialProviderCredential* pcpc,
                                         [in] DWORD dwFieldID,
                                         [in] DWORD dwSelectedItem);
    HRESULT DeleteFieldComboBoxItem([in] ICredentialProviderCredential* pcpc,
                                    [in] DWORD dwFieldID,
                                    [in] DWORD dwItem);
    HRESULT AppendFieldComboBoxItem([in] ICredentialProviderCredential* pcpc,
                                    [in] DWORD dwFieldID,
                                    [in, string] LPCWSTR pszItem);

    HRESULT SetFieldSubmitButton([in] ICredentialProviderCredential* pcpc,
                                 [in] DWORD dwFieldID,
                                 [in] DWORD dwAdjacentTo);
    HRESULT OnCreatingWindow([out] HWND* phwndOwner);
};

interface ICredentialProviderEvents; // forward

[
    local,
    object,
    pointer_default(ref),
    uuid(d27c3481-5a1c-45b2-8aaa-c20ebbe8229e),
]
interface ICredentialProvider : IUnknown
{
    HRESULT SetUsageScenario([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
                             [in] DWORD dwFlags);
    HRESULT SetSerialization([in, annotation("_In_")] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs);

    HRESULT Advise([in, annotation("_In_")] ICredentialProviderEvents* pcpe, [in, annotation("_In_")] UINT_PTR upAdviseContext);
    HRESULT UnAdvise();

    HRESULT GetFieldDescriptorCount([out, annotation("_Out_")] DWORD* pdwCount);
    HRESULT GetFieldDescriptorAt([in] DWORD dwIndex,
                                 [out, annotation("_Outptr_result_nullonfailure_")] CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd);

    HRESULT GetCredentialCount([out, annotation("_Out_")] DWORD* pdwCount,
                               [out, annotation("_Out_")] DWORD* pdwDefault,
                               [out, annotation("_Out_")] BOOL* pbAutoLogonWithDefault);
    HRESULT GetCredentialAt([in] DWORD dwIndex,
                            [out, annotation("_COM_Outptr_")] ICredentialProviderCredential** ppcpc);
};

[
    object,
    pointer_default(ref),
    uuid(34201e5a-a787-41a3-a5a4-bd6dcf2a854e),
]
interface ICredentialProviderEvents : IUnknown
{
    HRESULT CredentialsChanged([in] UINT_PTR upAdviseContext);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(a5da53f9-d475-4080-a120-910c4a739880),
]
interface ICredentialProviderFilter : IUnknown
{
    HRESULT Filter([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
                   [in] DWORD dwFlags,
                   [in, size_is(cProviders), annotation("_In_reads_(cProviders)")] GUID* rgclsidProviders,
                   [in, out, size_is(cProviders), annotation("_Inout_updates_(cProviders)")] BOOL* rgbAllow,
                   [in] DWORD cProviders);
    HRESULT UpdateRemoteCredential([in, annotation("_In_")] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn,
                                   [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut);
};

cpp_quote("#if (NTDDI_VERSION >= NTDDI_WIN8)")
[
    local,
    object,
    pointer_default(ref),
    uuid(fd672c54-40ea-4d6e-9b49-cfb1a7507bd7),
]
interface ICredentialProviderCredential2 : ICredentialProviderCredential
{
    HRESULT GetUserSid([out, string, annotation("_Outptr_result_maybenull_")] LPWSTR *sid);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(DBC6FB30-C843-49E3-A645-573E6F39446A),
]
interface ICredentialProviderCredentialWithFieldOptions : IUnknown
{
    HRESULT GetFieldOptions([in]  DWORD fieldID,
                            [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS *options);
};

[
    object,
    pointer_default(ref),
    uuid(B53C00B6-9922-4B78-B1F4-DDFE774DC39B),
]
interface ICredentialProviderCredentialEvents2 : ICredentialProviderCredentialEvents
{
    HRESULT BeginFieldUpdates();
    HRESULT EndFieldUpdates();
    HRESULT SetFieldOptions([in] ICredentialProviderCredential *credential,
                            [in] DWORD fieldID,
                            [in] CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS options);
};

[
    local,
    uuid(13793285-3ea6-40fd-b420-15f47da41fbb),
    object,
    pointer_default(ref),
]
interface ICredentialProviderUser : IUnknown
{
    HRESULT GetSid([out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR *sid);
    HRESULT GetProviderID([out, annotation("_Out_")] GUID *providerID);
    HRESULT GetStringValue([in, annotation("_In_")] REFPROPERTYKEY key, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR *stringValue);
    HRESULT GetValue([in, annotation("_In_")] REFPROPERTYKEY key, [out, annotation("_Out_")] PROPVARIANT *value);
};

// Identity_LocalUserProvider: {A198529B-730F-4089-B646-A12557F5665E}
// Define the provider GUID to pass as guidProivderToFilterTo in ICredentialProviderUserArray::SetProviderFilter() to populate local users.
cpp_quote("DEFINE_GUID(Identity_LocalUserProvider, 0xA198529B, 0x730F, 0x4089, 0xB6, 0x46, 0xA1, 0x25, 0x57, 0xF5, 0x66, 0x5E);")

[
    local,
    uuid(90C119AE-0F18-4520-A1F1-114366A40FE8),
    object,
    pointer_default(ref),
]
interface ICredentialProviderUserArray : IUnknown
{
    HRESULT SetProviderFilter([in] REFGUID guidProviderToFilterTo);
    HRESULT GetAccountOptions([out, annotation("_Out_")] CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS *credentialProviderAccountOptions);
    HRESULT GetCount([out, annotation("_Out_")] DWORD *userCount);
    HRESULT GetAt([in] DWORD userIndex, [out, annotation("_COM_Outptr_")] ICredentialProviderUser **user);
};

[
    local,
    uuid(095c1484-1c0c-4388-9c6d-500e61bf84bd),
    object,
    pointer_default(ref),
]
interface ICredentialProviderSetUserArray : IUnknown
{
    HRESULT SetUserArray([in, annotation("_In_")] ICredentialProviderUserArray *users);
};

cpp_quote("#endif // (NTDDI_VERSION >= NTDDI_WIN8)")

cpp_quote("#if (NTDDI_VERSION >= NTDDI_WINTHRESHOLD)")
[
    local,
    object,
    pointer_default(ref),
    uuid(64A5010E-4363-41F8-9738-19045C20DABC),
]
interface ICredentialProviderCredential3 : ICredentialProviderCredential2
{
    HRESULT GetBitmapBufferValue([in] DWORD fieldID,
                          [in, out, annotation("_Out_")] DWORD* pImageBufferSize,
                          [out, size_is(, *pImageBufferSize), annotation("_Outptr_result_bytebuffer_(*pImageBufferSize) _Result_nullonfailure_")] BYTE** ppImageBuffer);
};

[
    object,
    pointer_default(ref),
    uuid(2D8DEEB8-1322-4973-8DF9-B282F2468290),
]
interface ICredentialProviderCredentialEvents3 : ICredentialProviderCredentialEvents2
{
    HRESULT SetFieldBitmapBuffer([in] ICredentialProviderCredential* pcpc,
                          [in] DWORD fieldID,
                          [in] DWORD imageBufferSize,
                          [in, size_is(imageBufferSize)] BYTE const* pImageBuffer);
};

[
    local,
    uuid(712DF3E5-BAF7-47F5-9131-DB2DA3B02C93),
    object,
    pointer_default(ref),
]
interface ICredentialProviderUserArray2 : ICredentialProviderUserArray
{
    HRESULT SetProviderFilters([in, size_is(cProviders), annotation("_In_reads_(cProviders)")] GUID* rgclsidProvidersToFilterTo,
        [in] DWORD cProviders);
};

cpp_quote("#endif // (NTDDI_VERSION >= NTDDI_WINTHRESHOLD)")

//
// This typelib contains the CLSIDs of Microsoft's ICredentialProvider implementations.
//
[
    uuid(d545db01-e522-4a63-af83-d8ddf954004f), // LIBID_CredentialProviders
]
library CredentialProviders
{
    // CLSID_PasswordCredentialProvider
    [ uuid(60b78e88-ead8-445c-9cfd-0b87f74ea6cd) ] coclass PasswordCredentialProvider { interface ICredentialProvider; }

    // CLSID_V1PasswordCredentialProvider
    [ uuid(6f45dc1e-5384-457a-bc13-2cd81b0d28ed) ] coclass V1PasswordCredentialProvider { interface ICredentialProvider; }

    // CLSID_PINLogonCredentialProvider
    [ uuid(cb82ea12-9f71-446d-89e1-8d0924e1256e) ] coclass PINLogonCredentialProvider { interface ICredentialProvider; }

    // CLSID_NPCredentialProvider
    [ uuid(3dd6bec0-8193-4ffe-ae25-e08e39ea4063) ] coclass NPCredentialProvider { interface ICredentialProvider; }

    // CLSID_SmartcardCredentialProvider
    [ uuid(8FD7E19C-3BF7-489B-A72C-846AB3678C96) ] coclass SmartcardCredentialProvider { interface ICredentialProvider; }

    // CLSID_V1SmartcardCredentialProvider
    [ uuid(8bf9a910-a8ff-457f-999f-a5ca10b4a885) ] coclass V1SmartcardCredentialProvider { interface ICredentialProvider; }

    // CLSID_SmartcardPinProvider
    [ uuid(94596c7e-3744-41ce-893e-bbf09122f76a) ] coclass SmartcardPinProvider { interface ICredentialProvider; }

    // CLSID_SmartcardReaderSelectionProvider
    [ uuid(1b283861-754f-4022-ad47-a5eaaa618894) ] coclass SmartcardReaderSelectionProvider { interface ICredentialProvider; }

    // CLSID_SmartcardWinRTProvider
    [ uuid(1ee7337f-85ac-45e2-a23c-37c753209769) ] coclass SmartcardWinRTProvider { interface ICredentialProvider; }

    // CLSID_GenericCredentialProvider
    [ uuid(25CBB996-92ED-457e-B28C-4774084BD562) ] coclass GenericCredentialProvider { interface ICredentialProvider; }

    // CLSID_RASProvider
    [ uuid(5537E283-B1E7-4EF8-9C6E-7AB0AFE5056D) ] coclass RASProvider { interface ICredentialProvider; }

    // CLSID_OnexCredentialProvider
    [ uuid(07AA0886-CC8D-4e19-A410-1C75AF686E62) ] coclass OnexCredentialProvider { interface ICredentialProvider; }

    // CLSID_OnexPlapSmartcardCredentialProvider
    [ uuid(33c86cd6-705f-4ba1-9adb-67070b837775) ] coclass OnexPlapSmartcardCredentialProvider { interface ICredentialProvider; }

    // CLSID_VaultProvider
    [ uuid(503739d0-4c5e-4cfd-b3ba-d881334f0df2) ] coclass VaultProvider { interface ICredentialProvider; }

    // CLSID_WinBioCredentialProvider
    [ uuid(BEC09223-B018-416D-A0AC-523971B639F5) ] coclass WinBioCredentialProvider { interface ICredentialProvider; }

    // CLSID_V1WinBioCredentialProvider
    [ uuid(AC3AC249-E820-4343-A65B-377AC634DC09) ] coclass V1WinBioCredentialProvider { interface ICredentialProvider; }
};

cpp_quote("#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */")
#pragma endregion

