Ejemplo n.º 1
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);
            }
        }