SAML Single Sign On (SSO) into Bitbucket using Shibboleth 3

Bitbucket SAML app gives the ability to enable SAML Single Sign On for Bitbucket Software. Bitbucket Software is compatible with all SAML Identity Providers. Here we will go through a guide to configure SSO between Bitbucket and Shibboleth 3. By the end of this guide, Shibboleth 3 users should be able to login and register to Bitbucket Software.

Step 1: Setup Shibboleth3 as Identity Provider

  • In conf/idp.properties, uncomment and set 'idp.encryption.optional' to true.
       eg. idp.encryption.optional = true
  • In conf/metadata-providers.xml, configure Service Provider like this
  • <MetadataProvider xmlns:samlmd="urn:oasis:names:tc:SAML:2.0:metadata"
      id="miniOrangeInLineEntity" xsi:type="InlineMetadataProvider" sortKey="1">
      <samlmd:EntityDescriptor ID="entity" entityID="<SP-EntityID / Issuer from Service Provider Info tab in plugin.>"
        validUntil="2020-09-06T04:13:32Z">
        <samlmd:SPSSODescriptor AuthnRequestsSigned="false" WantAssertionsSigned="true"
        protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
          <samlmd:NameIDFormat>
            urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
          </samlmd:NameIDFormat>
        <samlmd:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
        Location="<ACS (AssertionConsumerService) URL from Step1 of the plugin under Identity Provider Tab.>"
          index="1" />
        </samlmd:SPSSODescriptor>
        </samlmd:EntityDescriptor>
    </MetadataProvider>
  • In conf/saml-nameid.properties, uncomment and set default NameID as Email Address like this
  • idp.nameid.saml2.default=urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
  • In conf/saml-nameid-xml, search for shibboleth.SAML2NameIDGenerators. Uncomment the shibboleth.SAML2AttributeSourcedGenerator bean and comment all other ref beans
  • <!-- SAML 2 NameID Generation -->
    <util:list id="shibboleth.SAML2NameIDGenerators">
      <!--<ref bean="shibboleth.SAML2TransientGenerator" /> -->
      <!-->ref bean="shibboleth.SAML2PersistentGenerator" /> -->
      <bean parent="shibboleth.SAML2AttributeSourcedGenerator"
      p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
      p:attributeSourceIds="#{ {'email'} }" />
    </util:list>
  • Make sure you have defined AttributeDefinition in conf/attribute-resolver.xml.
  • <!-- Note: AttributeDefinitionid must be same as what you provided in attributeSourceIds in conf/saml-nameid.xml -->
    <resolver:AttributeDefinitionxsi:type="ad:Simple" id="email" sourceAttributeID="mail">
      <resolver:Dependency ref="ldapConnector" />
      <resolver:AttributeEncoderxsi:type="enc:SAML2String" name="email" friendlyName="email" />
    </resolver:AttributeDefinition >

    <resolver:DataConnector id="ldapConnector" xsi:type="dc:LDAPDirectory" ldapURL="%{idp.authn.LDAP.ldapURL}"
      baseDN="%{idp.authn.LDAP.baseDN}" principal="%{idp.authn.LDAP.bindDN}"
      principalCredential="%{idp.authn.LDAP.bindDNCredential}">
      <dc:FilterTemplate>
        <!-- Define you User Search Filter here -->
        <![CDATA[ (&(objectclass=*)(cn=$requestContext.principalName)) ]]>
      </dc:FilterTemplate>

      <dc:ReturnAttributes>*</dc:ReturnAttributes>
    </resolver:DataConnector>
  • Make sure you have AttributeFilterPolicy defined in conf/attribute-filter.xml.
  • <afp:AttributeFilterPolicy id="ldapAttributes">
    <afp:PolicyRequirementRulexsi:type="basic:ANY"/>
      <afp:AttributeRuleattributeID="email">
        <afp:PermitValueRulexsi:type="basic:ANY"/>
      </afp:AttributeRule>
    </afp:AttributeFilterPolicy>
  • Restart the Shibboleth Server.
  • You need to configure these endpoints in the Service Provider.
  • IDP Entity ID https://<your_domain>/idp/shibboleth
    Single Login URL https://<your_domain>/idp/profile/SAML2/Redirect/SSO
    Single Logout URL https://<your_domain>/idp/shibboleth
    X.509 Certificate The public key certificate of your Shibboleth server

Step 2: Setup Bitbucket as Service Provider

Now we will go through the steps to setup Bitbucket as a Service Provider using miniOrange add-on:



Configuring IDP First Time

You can skip the Flow Driven setup by closing it by clicking on SKIP Quick Setup and continue with setting up using Single IDP Setup.

1. Click on the Configure button from the plugin's list. It will show you the following page to download the setup guide. Click Next


2. Note down the following information. This information is required for creating an application on IdP. Click Next.
  • SP Entity ID / Issuer
  • ACS URL
  • Certificate
bitbucket sso-1
3. We can configure IDP Settings in Bitbucket in four ways:

3.1. Using Metadata URL
Enter IDP Name, select IDP Metadata as URL & enter your IDP metadata URL in the given textbox. Click on Import to fetch IDP settings.

bitbucket sso-2
3.2. Using Metadata File
Enter IDP Name, select IDP Metadata as File & browse your IDP metadata file. Click on Import to fetch IDP settings.

bitbucket sso-3
3.3. Using Metadata Text
Enter IDP Name, select IDP Metadata as Text & add your IDP metadata XML content in the given text area. Click on Import to fetch IDP settings.

bitbucket sso-4
3.4. Manual Configuration
You can also configure IDP settings on Bitbucket manually. For that, you need to click here.

bitbucket sso-5
Enter the following details
  • IDP Entity ID /Issuer
  • Single Sign-on URL
  • Single Logout URL
  • IDP Signing Certificate
bitbucket sso-6
4. Enter username attribute name & email address attribute name from IDP. Click on the Save button after adding valid information. If you are not sure about this information, you can configure this later.

bitbucket sso-7
5. Click on Finish.

bitbucket sso-8
Configuring Single IDP

We can configure IDP settings in 3 ways:

A. By Metadata URL

  • Click on Import from Metadata in Configure IDP tab
  • Select IDP: Import From Metadata URL
  • Enter IDP metadata URL: Enter your metadata URL
  • If your IDP changes certificates at intervals, you can select Refresh metadata periodically. Select 5 minutes for the best results.
  • Click Import

bitbucket sso-8

B. By uploading Metadata XML file

  • Click on Import from Metadata in Configure IDP tab
  • Select IDP: Import from Metadata File
  • Upload metadata file
  • Click Import

bitbucket sso-9

C. Manual Configuration

Go to Configure IDP tab and enter the following details

  • IDP Entity ID
  • Single Sign On URL
  • Single Logout URL
  • X.509 Certificate
bitbucket sso-10

Step 3: Setting up Bitbucket user profile attributes

    We will be setting up user profile attributes for Bitbucket. If your users are stored in a directory that is Read Only, please check Disable Attribute Mapping in User Profile tab and follow steps given in Matching a User.

    bitbucket sso-11

    a. Finding correct attributes
  • Go to Configure IDP tab. Scroll down and click on Test Configuration.
  • You will see all the values returned by your IDP to Bitbucket in a table. If you don't see value for First Name, Last Name, Email or Username, make the required settings in your IDP to return this information.
  • Once you see all the values in Test Configuration, keep the window open and go to User Profile tab.
  • b. Setting profile attributes
  • In this tab, fill the values by matching the name of the attribute. For instance, if the Attribute Name in the Test Configuration window is NameID, enter NameID against Username
  • Setting up both Username and Email is required if you want to let users register. If you want existing users to the only login, configure the attribute using which you will match the user in Bitbucket.
  • c. Matching a User
    When the user logs into Bitbucket, one of the user's data/attribute coming in from the IDP is used to search the user in Bitbucket. This is used to detect the user in Bitbucket and log in the user to the same account.
  • Go to User Profile tab
  • Select Username or Email for Login/Search Bitbucket user account by
  • Enter the attribute name from IDP which corresponds to Username or Email using Finding Correct Attributes

Step 4: Assigning groups to users

    We will be setting up user group attributes for Bitbucket. If your users are stored in a directory that is Read Only, please check Disable Group Mapping in User Groups tab and skip to Setting default group.

    bitbucket sso-12
    a. Finding Group Attribute
  • Just like we found Attribute Name for User Profile attributes, we find group attribute.
  • Go to Configure IDP tab. Scroll down and click on Test Configuration.
  • You will see all the values returned by your IDP to Bitbucket in a table. If you don't see value with groups, make the required settings in your IDP to return group names.
  • Once you see all the values in Test Configuration, keep the window open and go to User Groups tab.
  • Enter the Attribute Name of group against Group Attribute
  • At the bottom of the page, all groups in Bitbucket are shown. You can map groups in IDP which correspond to Bitbucket groups. For example, if you want all users in dev-ops and dev groups in IDP to be added to crucible-users, you will need to enter dev-ops;dev against crucible-users
  • If you want user mapping to work for only limited groups in Bitbucket, check the option Update User Groups

  • b. Setting default group
  • Select the users' Default Group in the tab User Groups. If no group is mapped, users are added by default to this group.
  • You can enable default groups for all users or only new users using the option Enable Default Groups for.

Step 5: SSO Settings

    The settings in SSO Settings tab define the user experience for Single Sign On.
    a. Sign In Settings
  • Set button text for button on login page using Login Button Text
  • Set redirect URL after login using Relay State. Keep this empty for coming back to the same page user started from
  • Enable Auto-redirect to IDP if you want to allow users to login only using IDP. Enable backdoor for emergency
  • bitbucket sso-13
    b. Sign Out Settings
    Set Logout URL or Logout Template to redirect users after logout action.

    bitbucket sso-14
    c. SSO Error Settings
    Set error template to redirect users to a custom error page instead of login page. Use this if you have Auto-redirect to IDP enabled.

    bitbucket sso-15

Free Trial

If you are looking for anything which you cannot find, please drop us an email on info@miniorange.com