Legacy: Tyk Classic PortalYou’re viewing documentation for the Tyk Classic Portal, which is no longer actively maintained.If you’re looking for the latest API documentation for the new Tyk Developer Portal, please refer to the Postman collection or visit the Tyk Developer Portal section.The Classic Portal is in maintenance mode and will be deprecated soon. For questions or support, contact us at support@tyk.io.
By default, any user who accesses your developer Portal will be able to view all of the published APIs in the catalog. This behavior may not be desired and you may want to have more control of what APIs developers see in the catalog when accessing the portal. A common use case for this is if you have internal APIs that you want to publish only to your internal developers, and restrict view to others. We’ll walk through how you can use custom Page Templates to control the visibility of your APIs so it can only be seen by specific group of developers. In a nutshell, we are going to assign a group field to an API catalog profile, to a developer profile, and check if their group matched. Please note that this does not support multiple groups for a single API catalog entry, nor for a single developer profile.

Prerequisites

  1. You have an API created in your Dashboard. See Create an API for more details.
  2. You have a Policy created in your Dashboard that has access rights to this API
  3. You have a Portal Catalog entry for this API. Here we will call it “Internal API”
  4. You have a developer account that can access your Developer Portal.

Add a group field to the API Catalog profile

For this example, we’ll add a custom field to the Portal catalog “Group”. This group is set to “internal” which indicates that only developers in internal group shoud have access to the Catalog. Go to Portal Management > Catalog -> Your API screen portal_catalogue_fied_group

Add a custom field to the developer profile

For this example, we’ll add a custom field to the developer profile also called “Group”. This group is set set to “internal” it means that developer should have access to the catalogs with the same Group restriction. Go to Portal Management > Developers screen developer_field_group.png This flag can also be set programatically.

Modify the Portal Catalog Template to add Show/Hide Logic

The developer portal is fully customizable via templates. We’ll add custom logic to the portal catalog template (catalogue.html) to show/hide the “Internal API” catalog based on the value of the “Group” field for the developer. The main difference from the default template is two changes:
  1. Get user data state at the start of template: {{$profile := .UserData }}
  2. Before rendering api catalog element, which renders list of APIs, we insert the following section:
{{ $show := true }}

{{ range $field, $value := $apiDetail.Fields }}
	{{ $group_match := true }}
	{{ if (eq $field "Group") }}
		{{ $group_match = false }}
		{{ range $dfield, $dvalue := $profile.Fields }}
			{{ if eq $dfield "Group" }}
				{{ if eq $dvalue $value }}
					{{ $group_match = true }}
				{{ end }}
			{{ end }}
		{{ end }}
	{{ end }}

	{{ if not $group_match }}
		{{ $show = false }}
	{{ end }}
{{ end }}

{{if $show}}
{/* Render catalog */}
{{end}}
We’re now going to overwrite the default catalogue.html template in the ‘portal/templates’ directory on the Tyk Dashboard instance with the custom one above. NOTE: After replacing or updating a template, the Dashboard must be restarted to apply the changes. Now the visibility of the “Internal API” is driven by the value of the “Group” field on the developer profile.

Multiple API subscriptions

If you have enabled “Enable multiple API subscriptions” option in the portal settings, you also need to modify request_multi_key.html template. The main difference from the default template is two changes:
  1. Get user data state at the start of template: {{$profile := .UserData }}
  2. Before rendering <li> element, which renders list of APIs, we insert the following section:
{{ range $field, $value := $apiDetail.Fields }}
	{{ $group_match := true }}
	{{ if (eq $field "Group") }}
		{{ $group_match = false }}
		{{ range $dfield, $dvalue := $profile.Fields }}
			{{ if eq $dfield "Group" }}
				{{ if eq $dvalue $value }}
					{{ $group_match = true }}
				{{ end }}
			{{ end }}
		{{ end }}
	{{ end }}

	{{ if not $group_match }}
		{{ $match = true }}
	{{ end }}
{{ end }}

Developer Logged In, Group field set to internal (Internal API is visible)

dev_logged_in_internal

Developer Logged In, Group field not set or set so group other than internal (Internal API not visible)

dev_logged_in_external

No User Logged In (Internal API not visible)

no_user_logged_in