Click here to Skip to main content
15,886,864 members
Articles / Hosted Services / Azure
Tip/Trick

Ever Try to Retrieve Relying Party Application Authenticated Under ACS (an Identity and Access Management Middleware) or the RP Identity Provider Name

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
26 Apr 2018CPOL1 min read 4.1K  
RETRIEVE RELYING PARTY APPLICATION name and RP IDP Names

Introduction

In this article, we can retrieve Relying party application authenticated under ACS (an Identity And Access management middleware).

Background

Playing out with ACS to find RPs were a bit confusing but there are 2 ways which I found to be relevant and with few drawbacks.

Image 1

Reason why we need Retrieve Relying party application details are:

  1. To know some application sensitive information like tenant subscribed under which IDP and how many?
  2. To know the Count of Retrieve Relying party application in the ACS !

Using the Code

The below code is C# code.

Two different code are here one direct way of writing a method which grabs Relying Party on the basis of Tenant name who authenticated to your Application via ACS.

This code uses ACS Management Service internally when it calls up.

CreateManagementServiceClient

C#
//
// Code 1 :  
//
  public RelyingParty RetrieveRelyingParty(string name)
        {
            try
            {
                var client = this.CreateManagementServiceClient();
                return client.RelyingParties
                    .Expand("RelyingPartyAddresses/RelyingParty,
                    RelyingPartyIdentityProviders/IdentityProvider,
                    RelyingPartyIdentityProviders/IdentityProvider/Issuer,
                    RelyingPartyIdentityProviders/RelyingParty,
                    RelyingPartyKeys/RelyingParty,RelyingPartyRuleGroups/RelyingParty,
                    RelyingPartyRuleGroups/RuleGroup/Rules")

                    .Where(rp => rp.Name.Equals(name, StringComparison.OrdinalIgnoreCase))

                    .FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw this.TryGetExceptionDetails(ex);
            }
        }
//

This code also uses ACS Management Service internally but it does not fetch directly the Identity Providers of a particular tenant.

Follows steps like:

  1. Get all the relyingPartyList using Service Helper internally uses ACS Management Service
  2. Get all the identityProviderList
  3. Iterate over relyingPartyList to select the proper Tenant Relying Party you want to target to get the IDP name
  4. Iterate and get match of the Unique IDO ids from both the IDP list and RP list and then get the Corresponding IDP name
C#
// Code 2 :
ManagementServiceHelper serviceHelper = new ManagementServiceHelper
(acsData.AcsServiceNameSpace, acsData.AcsUserName, acsData.AcsPassword);
                        int count = serviceHelper.RetrieveRelyingParties().Count();
                        List<RelyingParty> relyingPartyList = 
                              serviceHelper.RetrieveRelyingParties().ToList();
                        List<IdentityProvider> identityProviderList = 
                              serviceHelper.RetrieveIdentityProviders().ToList();
                        foreach (var item in relyingPartyList)
                        {
                            if (item.Name.Equals(existingTenantData.TenantSlugName))
                            {
                                string selected_Idp_DisplayName = string.Empty;
                                string selected_IDP_ID = (from selectedIdp in 
                                identityProviderList select selectedIdp.Id).
                                                     FirstOrDefault().ToString();
                                foreach (var identityProvider in identityProviderList)
                                {
                                    foreach (var item2 in item.RelyingPartyIdentityProviders)
                                    {
                                        if (identityProvider.Id.Equals(item2.IdentityProviderId))
                                        {
                                            selected_Idp_DisplayName = identityProvider.DisplayName;
                                            message = selected_Idp_DisplayName;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                message = "Could not Find Identity Provider name 
                                           Corresponding to the Relying Party";
                            }
                        }

Hope this was useful...

References

History

  • 9th October, 2014 - Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Mindtree
India India
I am a person who thinks in varied directions rather than sticking or thinking the usual way and has tendency to learn new things........ always

Comments and Discussions

 
-- There are no messages in this forum --