/// <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); } } }
/// <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); } }
/// <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); } }