<?xml version='1.0' encoding='utf-8'?>
<!--
 Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved.
 Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
-->
<plugin id="cordova-plugin-ms-adal" version="0.10.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
    <name>ADAL for Cordova</name>
    <description>Provides Microsoft Azure Active Directory (ADAL) OAuth client.</description>

    <license>Apache 2.0</license>
    <keywords>microsoft, azure, adal, activedirectory</keywords>
    <repo>https://github.com/AzureAD/azure-activedirectory-library-for-cordova</repo>
    <issue>https://github.com/AzureAD/azure-activedirectory-library-for-cordova/issues</issue>

    <dependency id="cordova-plugin-compat" version="^1.0.0" />

    <engines>
        <!-- Required gradle functionality support -->
        <engine name="cordova-android" version=">=4.1.0" />
        <!-- Cordova 5.4.0 and Windows 4.1.0 are required for framework.target-dir support -->
        <engine name="cordova" version=">=5.4.0" />
        <engine name="cordova-windows" version=">=4.1.0" />
    </engines>

    <js-module name="utility" src="www/utility.js">
        <runs />
    </js-module>

    <js-module name="AuthenticationContext" src="www/AuthenticationContext.js">
        <clobbers target="Microsoft.ADAL.AuthenticationContext" />
    </js-module>

    <js-module name="CordovaBridge" src="www/CordovaBridge.js"/>
    <js-module name="AuthenticationResult" src="www/AuthenticationResult.js"/>
    <js-module name="TokenCache" src="www/TokenCache.js"/>
    <js-module name="TokenCacheItem" src="www/TokenCacheItem.js"/>
    <js-module name="UserInfo" src="www/UserInfo.js"/>
    <js-module name="LogItem" src="www/LogItem.js"/>

    <js-module name="AuthenticationSettings" src="www/AuthenticationSettings.js">
        <clobbers target="Microsoft.ADAL.AuthenticationSettings" />
    </js-module>

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="ADALProxy">
                <param name="android-package" value="com.microsoft.aad.adal.CordovaAdalPlugin"/>
            </feature>
        </config-file>
        <config-file target="AndroidManifest.xml" parent="/manifest">
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
            <uses-permission android:name="android.permission.GET_ACCOUNTS" />
            <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
            <uses-permission android:name="android.permission.USE_CREDENTIALS" />
        </config-file>

        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <activity android:name="com.microsoft.aad.adal.AuthenticationActivity"
                android:configChanges="orientation|keyboardHidden|screenSize">
            </activity>
        </config-file>

        <framework src="src/android/adal.gradle" custom="true" type="gradleReference" />

        <source-file src="src/android/CordovaAdalPlugin.java" target-dir="src/com/microsoft/aad/adal" />
        <source-file src="src/android/DefaultAuthenticationCallback.java" target-dir="src/com/microsoft/aad/adal" />
        <source-file src="src/android/SimpleSerialization.java" target-dir="src/com/microsoft/aad/adal" />

    </platform>

    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="ADALProxy">
                <param name="ios-package" value="CordovaAdalPlugin" />
            </feature>
        </config-file>

        <header-file src="src/ios/CordovaAdalPlugin.h" />
        <source-file src="src/ios/CordovaAdalPlugin.m" />

        <header-file src="src/ios/CordovaAdalUtils.h" />
        <source-file src="src/ios/CordovaAdalUtils.m" />

        <framework src="src/ios/ADAL.framework" custom="true"/>

        <resource-file src="src/ios/ADALiOS.entitlements" />
        <hook type="after_plugin_install" src="scripts/configureEntitlementsIos.js" />
        <hook type="before_plugin_uninstall" src="scripts/configureEntitlementsIos.js" />

        <!-- (CB-11854) CODE_SIGN_ENTITLEMENTS for ios@4.3.0 and up -->
        <config-file target="*-Debug.plist" parent="keychain-access-groups">
            <array>
                <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
            </array>
        </config-file>
        <config-file target="*-Release.plist" parent="keychain-access-groups">
            <array>
                <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string>
            </array>
        </config-file>

        <!--
        Plist sections below are required for brokered authentication support
        https://github.com/AzureAD/azure-activedirectory-library-for-objc#brokered-authentication
        -->
        <config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
            <array>
                <string>msauth</string>
            </array>
        </config-file>

        <config-file target="*-Info.plist" parent="CFBundleURLTypes">
            <array>
                <dict>
                    <key>CFBundleTypeRole</key>
                    <string>Editor</string>
                    <key>CFBundleURLName</key>
                    <string>$(CFBundleIdentifier)</string>
                    <key>CFBundleURLSchemes</key>
                    <array>
                        <string>x-msauth-$(CFBundleIdentifier:rfc1034identifier)</string>
                    </array>
                </dict>
            </array>
        </config-file>
    </platform>

    <platform name="windows">
        <js-module src="src/windows/ADAL3Compat.js" name="ADAL3Compat">
            <merges target="Microsoft.IdentityModel" />
        </js-module>

        <js-module src="src/windows/ADALProxy.js" name="ADALProxy">
            <runs />
        </js-module>

        <framework src="src/windows/lib/wpa/Microsoft.IdentityModel.Clients.ActiveDirectory.winmd" target="phone" custom="true" target-dir="adal-wpa" versions="&lt;10" />
        <framework src="src/windows/lib/adal3/ADAL3WinMDProxy.csproj" target="win" custom="true" type="projectReference" />

        <!-- Needed to patch projitems so that the solution is correct right after plugin install -->
        <hook type="after_plugin_install" src="scripts/prePackage-windows.js" />

        <hook type="after_prepare" src="scripts/prePackage-windows.js" />
        <hook type="before_plugin_uninstall" src="scripts/beforeUninstall-windows.js" />
    </platform>
</plugin>
