示例#1
0
 private void ShowCreateDownParty(PartyTypes type, OAuthSubPartyTypes?oauthSubPartyType = null)
 {
     if (type == PartyTypes.Oidc)
     {
         var oidcDownParty = new GeneralOidcDownPartyViewModel();
         oidcDownParty.CreateMode = true;
         oidcDownParty.Edit       = true;
         downParties.Add(oidcDownParty);
     }
     else if (type == PartyTypes.OAuth2)
     {
         var oauthDownParty = new GeneralOAuthDownPartyViewModel();
         if (!oauthSubPartyType.HasValue)
         {
             throw new ArgumentNullException(nameof(oauthSubPartyType), "Required for OAuth 2.0 down parties.");
         }
         oauthDownParty.SubPartyType = oauthSubPartyType.Value;
         oauthDownParty.CreateMode   = true;
         oauthDownParty.Edit         = true;
         downParties.Add(oauthDownParty);
     }
     else if (type == PartyTypes.Saml2)
     {
         var samlDownParty = new GeneralSamlDownPartyViewModel();
         samlDownParty.CreateMode = true;
         samlDownParty.Edit       = true;
         downParties.Add(samlDownParty);
     }
 }
示例#2
0
        private OAuthDownPartyViewModel ToViewModel(GeneralOAuthDownPartyViewModel generalOAuthDownParty, OAuthDownParty oauthDownParty, List <OAuthClientSecretResponse> oauthDownSecrets)
        {
            return(oauthDownParty.Map <OAuthDownPartyViewModel>(afterMap =>
            {
                if (afterMap.Client == null)
                {
                    generalOAuthDownParty.EnableClientTab = false;
                }
                else
                {
                    generalOAuthDownParty.EnableClientTab = true;
                    afterMap.Client.ExistingSecrets = oauthDownSecrets.Select(s => new OAuthClientSecretViewModel {
                        Name = s.Name, Info = s.Info
                    }).ToList();
                    var defaultResourceScopeIndex = afterMap.Client.ResourceScopes.FindIndex(r => r.Resource.Equals(generalOAuthDownParty.Name, StringComparison.Ordinal));
                    if (defaultResourceScopeIndex > -1)
                    {
                        afterMap.Client.DefaultResourceScope = true;
                        var defaultResourceScope = afterMap.Client.ResourceScopes[defaultResourceScopeIndex];
                        if (defaultResourceScope.Scopes?.Count() > 0)
                        {
                            foreach (var scope in defaultResourceScope.Scopes)
                            {
                                afterMap.Client.DefaultResourceScopeScopes.Add(scope);
                            }
                        }
                        afterMap.Client.ResourceScopes.RemoveAt(defaultResourceScopeIndex);
                    }
                    else
                    {
                        afterMap.Client.DefaultResourceScope = false;
                    }

                    afterMap.Client.ScopesViewModel = afterMap.Client.Scopes.Map <List <OAuthDownScopeViewModel> >() ?? new List <OAuthDownScopeViewModel>();
                }

                if (afterMap.Resource == null)
                {
                    generalOAuthDownParty.EnableResourceTab = false;
                }
                else
                {
                    generalOAuthDownParty.EnableResourceTab = true;
                }

                if (afterMap.ClaimTransforms?.Count > 0)
                {
                    afterMap.ClaimTransforms = afterMap.ClaimTransforms.MapClaimTransforms();
                }
            }));
        }
示例#3
0
        private void OAuthDownPartyViewModelAfterInit(GeneralOAuthDownPartyViewModel oauthDownParty, OAuthDownPartyViewModel model)
        {
            if (oauthDownParty.CreateMode)
            {
                model.Client   = oauthDownParty.EnableClientTab ? new OAuthDownClientViewModel() : null;
                model.Resource = oauthDownParty.EnableResourceTab ? new OAuthDownResource() : null;

                if (model.Client != null)
                {
                    model.Client.ResponseTypes.Add("code");
                    model.Client.ScopesViewModel.Add(new OAuthDownScopeViewModel {
                        Scope = IdentityConstants.DefaultOidcScopes.OfflineAccess
                    });
                }
            }
        }
示例#4
0
        private async Task DeleteOAuthDownPartyAsync(GeneralOAuthDownPartyViewModel generalOAuthDownParty)
        {
            try
            {
                await DownPartyService.DeleteOAuthDownPartyAsync(generalOAuthDownParty.Name);

                DownParties.Remove(generalOAuthDownParty);
                await OnStateHasChanged.InvokeAsync(DownParty);
            }
            catch (TokenUnavailableException)
            {
                await(OpenidConnectPkce as TenantOpenidConnectPkce).TenantLoginAsync();
            }
            catch (Exception ex)
            {
                generalOAuthDownParty.Form.SetError(ex.Message);
            }
        }
示例#5
0
        private void OAuthDownPartyViewModelAfterInit(GeneralOAuthDownPartyViewModel oauthDownParty, OAuthDownPartyViewModel model)
        {
            if (oauthDownParty.CreateMode)
            {
                if (oauthDownParty.SubPartyType == OAuthSubPartyTypes.Resource)
                {
                    oauthDownParty.EnableClientTab   = false;
                    oauthDownParty.EnableResourceTab = true;
                    oauthDownParty.ShowClientTab     = false;
                    oauthDownParty.ShowResourceTab   = true;

                    model.Resource = new OAuthDownResource();
                }
                else if (oauthDownParty.SubPartyType == OAuthSubPartyTypes.ClientCredentialsGrant)
                {
                    oauthDownParty.EnableClientTab   = true;
                    oauthDownParty.EnableResourceTab = false;
                    oauthDownParty.ShowClientTab     = true;
                    oauthDownParty.ShowResourceTab   = false;

                    model.Client = new OAuthDownClientViewModel();

                    model.Client.DefaultResourceScope = false;

                    model.Client.RequirePkce = false;
                    model.Client.Secrets     = new List <string> {
                        SecretGenerator.GenerateNewSecret()
                    };

                    model.Client.ResponseTypes.Add("token");
                }
                else
                {
                    throw new NotSupportedException("OAuthSubPartyTypes not supported.");
                }
            }
        }
示例#6
0
 private void ShowCreateDownParty(PartyTypes type)
 {
     if (type == PartyTypes.Oidc)
     {
         var oidcDownParty = new GeneralOidcDownPartyViewModel();
         oidcDownParty.CreateMode = true;
         oidcDownParty.Edit       = true;
         downParties.Add(oidcDownParty);
     }
     else if (type == PartyTypes.OAuth2)
     {
         var oauthDownParty = new GeneralOAuthDownPartyViewModel();
         oauthDownParty.CreateMode = true;
         oauthDownParty.Edit       = true;
         downParties.Add(oauthDownParty);
     }
     else if (type == PartyTypes.Saml2)
     {
         var samlDownParty = new GeneralSamlDownPartyViewModel();
         samlDownParty.CreateMode = true;
         samlDownParty.Edit       = true;
         downParties.Add(samlDownParty);
     }
 }
示例#7
0
        private async Task OnEditOAuthDownPartyValidSubmitAsync(GeneralOAuthDownPartyViewModel generalOAuthDownParty, EditContext editContext)
        {
            try
            {
                if (generalOAuthDownParty.Form.Model.ClaimTransforms?.Count() > 0)
                {
                    foreach (var claimTransform in generalOAuthDownParty.Form.Model.ClaimTransforms)
                    {
                        if (claimTransform is OAuthClaimTransformClaimInViewModel claimTransformClaimIn && !claimTransformClaimIn.ClaimIn.IsNullOrWhiteSpace())
                        {
                            claimTransform.ClaimsIn = new List <string> {
                                claimTransformClaimIn.ClaimIn
                            };
                        }
                    }
                }

                var oauthDownParty = generalOAuthDownParty.Form.Model.Map <OAuthDownParty>(afterMap: afterMap =>
                {
                    if (generalOAuthDownParty.Form.Model.Client?.DefaultResourceScope == true)
                    {
                        afterMap.Client.ResourceScopes.Add(new OAuthDownResourceScope {
                            Resource = generalOAuthDownParty.Form.Model.Name, Scopes = generalOAuthDownParty.Form.Model.Client.DefaultResourceScopeScopes
                        });
                    }
                    if (!(afterMap.Resource?.Scopes?.Count > 0))
                    {
                        afterMap.Resource = null;
                    }
                    if (generalOAuthDownParty.Form.Model.Client?.ScopesViewModel?.Count() > 0)
                    {
                        afterMap.Client.Scopes = generalOAuthDownParty.Form.Model.Client.ScopesViewModel.Map <List <OAuthDownScope> >();
                    }
                    if (afterMap.ClaimTransforms?.Count() > 0)
                    {
                        int order = 1;
                        foreach (var claimTransform in afterMap.ClaimTransforms)
                        {
                            claimTransform.Order = order++;
                        }
                    }
                });

                OAuthDownParty oauthDownPartyResult;
                if (generalOAuthDownParty.CreateMode)
                {
                    oauthDownPartyResult = await DownPartyService.CreateOAuthDownPartyAsync(oauthDownParty);
                }
                else
                {
                    oauthDownPartyResult = await DownPartyService.UpdateOAuthDownPartyAsync(oauthDownParty);

                    if (oauthDownParty.Client != null)
                    {
                        foreach (var existingSecret in generalOAuthDownParty.Form.Model.Client.ExistingSecrets.Where(s => s.Removed))
                        {
                            await DownPartyService.DeleteOAuthClientSecretDownPartyAsync(existingSecret.Name);
                        }
                    }
                }
                if (oauthDownParty.Client != null && generalOAuthDownParty.Form.Model.Client.Secrets.Count() > 0)
                {
                    await DownPartyService.CreateOAuthClientSecretDownPartyAsync(new OAuthClientSecretRequest { PartyName = generalOAuthDownParty.Form.Model.Name, Secrets = generalOAuthDownParty.Form.Model.Client.Secrets });
                }

                var oauthDownSecrets = await DownPartyService.GetOAuthClientSecretDownPartyAsync(oauthDownPartyResult.Name);

                generalOAuthDownParty.Form.UpdateModel(ToViewModel(generalOAuthDownParty, oauthDownPartyResult, oauthDownSecrets));
                if (generalOAuthDownParty.CreateMode)
                {
                    generalOAuthDownParty.CreateMode = false;
                    toastService.ShowSuccess("OAuth Down-party created.", "SUCCESS");
                }
                else
                {
                    toastService.ShowSuccess("OAuth Down-party updated.", "SUCCESS");
                }
                generalOAuthDownParty.Name = generalOAuthDownParty.Form.Model.Name;
            }
            catch (FoxIDsApiException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    generalOAuthDownParty.Form.SetFieldError(nameof(generalOAuthDownParty.Form.Model.Name), ex.Message);
                }
                else
                {
                    throw;
                }
            }
        }
示例#8
0
 private void OnOAuthDownPartyResourceTabChange(GeneralOAuthDownPartyViewModel oauthDownParty, bool enableTab) => oauthDownParty.Form.Model.Resource = enableTab ? new OAuthDownResource() : null;
示例#9
0
 private void OnOAuthDownPartyClientTabChange(GeneralOAuthDownPartyViewModel oauthDownParty, bool enableTab) => oauthDownParty.Form.Model.Client = enableTab ? new OAuthDownClientViewModel() : null;