Example #1
0
        ///<inheritdoc/>
        protected override async Task RenewAccessTokenAsync()
        {
            AuthenticationResult result;

            try
            {
                result = await PublicClient.AcquireTokenSilent(ApiTokenAccessArgs.Scopes, ApiTokenAccessArgs.UserAccount).ExecuteAsync();

                if (string.IsNullOrEmpty(result.AccessToken))
                {
                    throw new MsalUiRequiredException("404", "Access token was null");
                }
            }
            catch (MsalUiRequiredException)
            {
                result = await PublicClient.AcquireTokenInteractive(ApiTokenAccessArgs.Scopes)
                         .WithB2CAuthority(AuthoritySUSI)
                         .WithAccount(ApiTokenAccessArgs.UserAccount)
                         .WithParentActivityOrWindow(Context.GetMainWindow())
                         .ExecuteAsync()
                         .ConfigureAwait(false);
            }
            catch
            {
                throw;
            }
            AccessToken = AccessToken.Bearer(result.AccessToken, result.ExpiresOn);

            IdToken = result.IdToken;

            TokenRenewed?.Invoke(result);
        }
Example #2
0
 /// <summary>
 /// Fire the <see cref="TokenRenewed"/> event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnTokenRenewed(TokenRenewedEventArgs e)
 {
     TokenRenewed?.Invoke(this, e);
 }