Exemplo n.º 1
0
        private static AuthenticationContext GetAuthenticationContext(string userId, Permissions permissions)
        {
            var signedInUserID = permissions == Permissions.Delegated ? userId : Constants.AADTenantId;
            var tokenCache     = ADALTokenCache.Create(signedInUserID);

            return(new AuthenticationContext(Constants.Authority, tokenCache));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get an instance of AuthenticationContext
        /// </summary>
        public static AuthenticationContext GetAuthenticationContext(ClaimsIdentity claimsIdentity, Permissions permissions)
        {
            var tenantID       = claimsIdentity.GetTenantId();
            var userId         = claimsIdentity.GetObjectIdentifier();
            var signedInUserID = permissions == Permissions.Delegated ? userId : tenantID;

            var authority  = string.Format("{0}{1}", Constants.AADInstance, tenantID);
            var tokenCache = ADALTokenCache.Create(signedInUserID);

            return(new AuthenticationContext(authority, tokenCache));
        }
Exemplo n.º 3
0
        public async Task ClearDataAsync(IDialogContext context, LuisResult result)
        {
            context.UserData.Clear();
            context.ConversationData.Clear();

            var user = await context.GetTeamsAccountAsync();

            var tokenCache = ADALTokenCache.Create(user.ObjectId);

            tokenCache.Clear();

            await context.SayAsync("User & Conversation data were cleared. Token cache was cleared");

            context.Wait(MessageReceived);
        }
Exemplo n.º 4
0
        public async Task <string> GetTokenForApplication()
        {
            string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
            string tenantID       = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
            string userObjectID   = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

            // get a token for the Graph without triggering any user interaction (from the cache, via multi-resource refresh token, etc)
            ClientCredential clientcred = new ClientCredential(clientId, appKey);
            // initialize AuthenticationContext with the token cache of the currently signed in user, as kept in the app's database
            AuthenticationContext authenticationContext = new AuthenticationContext(aadInstance + tenantID, ADALTokenCache.Create(signedInUserID));
            AuthenticationResult  authenticationResult  = await authenticationContext.AcquireTokenSilentAsync(graphResourceID, clientcred, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

            return(authenticationResult.AccessToken);
        }