Exemple #1
0
        /// <summary>
        /// Reads an app handle by an app key. If app handle is not found, it returns null
        /// </summary>
        /// <param name="appKey">app key</param>
        /// <returns>Corresponding app handle (throws exception if app key is invalid)</returns>
        protected async Task <string> ReadAppHandle(string appKey)
        {
            // Lookup the appKey to resolve the appHandle
            IAppLookupEntity appLookupEntity = await this.appsManager.ReadAppByAppKey(appKey);

            return(appLookupEntity?.AppHandle);
        }
        /// <summary>
        /// Update app key index
        /// </summary>
        /// <param name="storageConsistencyMode">Storage consistency mode</param>
        /// <param name="appKey">App key</param>
        /// <param name="appLookupEntity">App lookup entity</param>
        /// <returns>Create app key index task</returns>
        public async Task UpdateAppKeyIndex(
            StorageConsistencyMode storageConsistencyMode,
            string appKey,
            IAppLookupEntity appLookupEntity)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.AppKeys);

            ObjectTable table     = this.tableStoreManager.GetTable(ContainerIdentifier.AppKeys, TableIdentifier.AppKeysIndex) as ObjectTable;
            Operation   operation = Operation.Replace(table, appKey, appKey, appLookupEntity as AppLookupEntity);
            await store.ExecuteOperationAsync(operation, storageConsistencyMode.ToConsistencyMode());
        }
        /// <summary>
        /// Get the app handle of a specific application (lookup by appKey)
        /// </summary>
        /// <param name="args">command line args</param>
        /// <returns>a task</returns>
        private async Task GetAppHandle(string[] args)
        {
            this.ParseGetAppHandleArgs(args);

            this.ValidateGetAppHandle();

            IAppLookupEntity appEntity = await this.appsManager.ReadAppByAppKey(this.appKey);

            if (appEntity != null)
            {
                Console.WriteLine($"AppHandle = {appEntity.AppHandle} for application with appKey = {this.appKey}");
            }
            else
            {
                Console.WriteLine($"Cannot find app with appKey = {this.appKey}");
            }
        }
Exemple #4
0
        /// <summary>
        /// Validates an app key
        /// </summary>
        /// <param name="appKey">app key</param>
        /// <returns>true or false</returns>
        protected async Task <bool> ValidateAppKey(string appKey)
        {
            appKey.IfNullOrEmptyThrowEx("CommonAuthManager:ValidateAppKey: appKey is null");

            // Lookup the appKey to resolve the appHandle
            IAppLookupEntity appLookupEntity = await this.appsManager.ReadAppByAppKey(appKey);

            if (appLookupEntity == null)
            {
                // The app key is not found (i.e., not bound to an app handle). One possibility is that the appKey
                // used to exist but was invalidated via the dev portal.
                string errorMessage = $"CommonAuthManager:ValidateAppKey: appKey not found. appKey: {appKey}";
                this.Log.LogError(errorMessage);
                return(false);
            }

            return(true);
        }