예제 #1
0
        /// <summary>
        /// Deletes an access token from the host OS.
        /// </summary>
        /// <param name="appId">An app/client id.</param>
        public static void DeleteToken(IAuthContext authContext)
        {
            if (string.IsNullOrEmpty(authContext.ClientId))
            {
                throw new ArgumentNullException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ErrorConstants.Message.NullOrEmptyParameter,
                                                    nameof(authContext.ClientId)));
            }

            if (authContext.ContextScope == ContextScope.Process)
            {
                GraphSession.Instance.MSALToken = null;
            }
            else
            {
                if (Helpers.OperatingSystem.IsWindows())
                {
                    WindowsTokenCache.DeleteToken(authContext.ClientId);
                }
                else if (Helpers.OperatingSystem.IsMacOS())
                {
                    MacTokenCache.DeleteToken(authContext.ClientId);
                }
                else
                {
                    LinuxTokenCache.DeleteToken(authContext.ClientId);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Encrypts and saves an access token buffer to the host platform OS.
        /// </summary>
        /// <param name="appId">An app/client id.</param>
        /// <param name="accessToken">An access token.</param>
        public static void SetToken(IAuthContext authContext, byte[] accessToken)
        {
            if (string.IsNullOrEmpty(authContext.ClientId))
            {
                throw new ArgumentNullException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ErrorConstants.Message.NullOrEmptyParameter,
                                                    nameof(authContext.ClientId)));
            }
            if (accessToken == null || accessToken.Length == 0)
            {
                return;
            }

            if (authContext.ContextScope == ContextScope.Process)
            {
                GraphSession.Instance.MSALToken = accessToken;
            }
            else if (authContext.ContextScope == ContextScope.CurrentUser)
            {
                if (Helpers.OperatingSystem.IsWindows())
                {
                    WindowsTokenCache.SetToken(authContext.ClientId, accessToken);
                }
                else if (Helpers.OperatingSystem.IsMacOS())
                {
                    MacTokenCache.SetToken(authContext.ClientId, accessToken);
                }
                else
                {
                    LinuxTokenCache.SetToken(authContext.ClientId, accessToken);
                }
            }
        }
        /// <summary>
        /// Encrypts and saves an access token buffer to the host platform OS.
        /// </summary>
        /// <param name="appId">An app/client id.</param>
        /// <param name="accessToken">An access token.</param>
        public static void SetToken(string appId, byte[] accessToken)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ErrorConstants.Message.NullOrEmptyParameter,
                                                    nameof(appId)));
            }
            if (accessToken == null || accessToken.Length == 0)
            {
                return;
            }

            if (Helpers.OperatingSystem.IsWindows())
            {
                WindowsTokenCache.SetToken(appId, accessToken);
            }
            else if (Helpers.OperatingSystem.IsMacOS())
            {
                MacTokenCache.SetToken(appId, accessToken);
            }
            else
            {
                LinuxTokenCache.SetToken(appId, accessToken);
            }
        }
예제 #4
0
 /// <summary>
 /// Decrypts the passed buffer based on the host platform.
 /// </summary>
 /// <param name="buffer">A <see cref="byte[]"/> to decrypt.</param>
 /// <returns>An decrypted <see cref="byte[]"/>.</returns>
 public static byte[] DecryptToken(byte[] buffer)
 {
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         return(WindowsTokenCache.DecryptToken(buffer));
     }
     return(buffer);
 }
        /// <summary>
        /// Deletes an access token from the host OS.
        /// </summary>
        /// <param name="appId">An app/client id.</param>
        public static void DeleteToken(string appId)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException(string.Format(
                                                    CultureInfo.CurrentCulture,
                                                    ErrorConstants.Message.NullOrEmptyParameter,
                                                    nameof(appId)));
            }

            if (Helpers.OperatingSystem.IsWindows())
            {
                WindowsTokenCache.DeleteToken(appId);
            }
            else if (Helpers.OperatingSystem.IsMacOS())
            {
                MacTokenCache.DeleteToken(appId);
            }
            else
            {
                LinuxTokenCache.DeleteToken(appId);
            }
        }