public async Task AcquireToken()

in dotNet/AuthEdge/AuthEdge.cs [35:81]


        public async Task<object> AcquireToken(object input)
        {
            var inputDict = input as IDictionary<string, object>;

            if (inputDict == null)
            {
                throw new ArgumentException("input");
            }

            string clientId = inputDict["ClientId"] as string;
            string replyUri = inputDict["ReplyUri"] as string;
            string resourceId = inputDict["ResourceId"] as string;
            string cacheLocation = inputDict["CacheLocation"] as string;
            AuthResult authResult = new AuthResult();

            if (this.ctx == null)
            {
                this.ctx = GetAuthenticationContext(null, cacheLocation);
            }

            try
            {
                AuthenticationResult result =
                    await Task.Run(() => this.ctx.AcquireTokenSilentAsync(resourceId, clientId));

                authResult.Scheme = "Bearer";
                authResult.Parameter = result.AccessToken;
            }
            catch (AdalException)
            {
                AuthenticationResult result =
                    this.ctx.AcquireTokenAsync(
                        resourceId,
                        clientId,
                        new Uri(replyUri),
                        new PlatformParameters(PromptBehavior.RefreshSession)).Result;

                authResult.Scheme = "Bearer";
                authResult.Parameter = result.AccessToken;
            }
            catch (Exception ex)
            {
                authResult.Error = ex.Message;
            }

            return authResult;
        }