Generate api by tyk-dashboard-api can not create oauth client

I tried to create an api via tyk dashboard api with oauth2.0. I call it api1
It created sucessfully with

  "api_definition": {
    "name": "Authentication",
    "slug": "auth",
    "org_id": "58648a2a572bf80001fba725",
    "use_keyless": false,
    "use_oauth2": true,
    "use_openid": false,
    "openid_options": {
        "providers": [],
        "segregate_by_client": false
    },
    "oauth_meta": {
        "allowed_access_types": [
            "refresh_token",
            "client_credentials"
        ],
        "allowed_authorize_types": [
            "code"
        ],
        "auth_login_redirect": ""
    },
    "auth": {
        "use_param": false,
        "param_name": "",
        "use_cookie": false,
        "cookie_name": "",
        "auth_header_name": "Authorization"
    },
    "use_basic_auth": false,
    "enable_jwt": false,
    "use_standard_auth": false,
    "enable_coprocess_auth": false,
    "jwt_signing_method": "",
    "jwt_source": "",
    "jwt_identity_base_field": "",
    "jwt_client_base_field": "",
    "jwt_policy_field_name": "",
    "notifications": {
        "shared_secret": "",
        "oauth_on_keychange_url": ""
    },
    "enable_signature_checking": false,
    "hmac_allowed_clock_skew": -1,
    "base_identity_provided_by": "",
    "definition": {
        "location": "header",
        "key": "x-api-version"
    },
    "version_data": {
        "not_versioned": true,
        "versions": {
            "Default": {
                "name": "Default",
                "expires": "",
                "paths": {
                    "ignored": [],
                    "white_list": [],
                    "black_list": []
                },
                "use_extended_paths": true,
                "extended_paths": {},
                "global_headers": {},
                "global_headers_remove": [],
                "global_size_limit": 0,
                "override_target": ""
            }
        }
    },
    "uptime_tests": {
        "check_list": [],
        "config": {
            "expire_utime_after": 0,
            "service_discovery": {
                "use_discovery_service": false,
                "query_endpoint": "",
                "use_nested_query": false,
                "parent_data_path": "",
                "data_path": "",
                "port_data_path": "",
                "target_path": "",
                "use_target_list": false,
                "cache_timeout": 60,
                "endpoint_returns_list": false
            },
            "recheck_wait": 0
        }
    },
    "proxy": {
        "preserve_host_header": false,
        "listen_path": "/auth/",
        "target_url": "https://www.parcelperform.com/",
        "strip_listen_path": true,
        "enable_load_balancing": false,
        "target_list": [],
        "check_host_against_uptime_tests": false,
        "service_discovery": {
            "use_discovery_service": false,
            "query_endpoint": "",
            "use_nested_query": false,
            "parent_data_path": "",
            "data_path": "hostname",
            "port_data_path": "port",
            "target_path": "/api-slug",
            "use_target_list": false,
            "cache_timeout": 60,
            "endpoint_returns_list": false
        }
    },
    "disable_rate_limit": false,
    "disable_quota": false,
    "custom_middleware": {
        "pre": [],
	"post": [],
        "post_key_auth": [],
        "auth_check": {
            "name": "",
            "path": "",
            "require_session": false
        },
        "response": [],
        "driver": "",
        "id_extractor": {
            "extract_from": "",
            "extract_with": "",
            "extractor_config": {}
        }
    },
    "custom_middleware_bundle": "",
    "cache_options": {
        "cache_timeout": 60,
        "enable_cache": false,
        "cache_all_safe_requests": false,
        "cache_response_codes": [],
        "enable_upstream_cache_control": false
    },
    "session_lifetime": 0,
    "active": true,
    "auth_provider": {
        "name": "",
        "storage_engine": "",
        "meta": {}
    },
    "session_provider": {
        "name": "",
        "storage_engine": "",
        "meta": null
    },
    "event_handlers": {
        "events": {}
    },
    "enable_batch_request_support": false,
    "enable_ip_whitelisting": false,
    "allowed_ips": [],
    "dont_set_quota_on_create": false,
    "expire_analytics_after": 0,
    "response_processors": [],
    "CORS": {
        "enable": false,
        "allowed_origins": [],
        "allowed_methods": [],
        "allowed_headers": [],
        "exposed_headers": [],
        "allow_credentials": false,
        "max_age": 24,
        "options_passthrough": false,
        "debug": false
    },
    "domain": "",
    "do_not_track": false,
    "tags": [],
    "enable_context_vars": false
  }
}

Its ok, but I can not create app client for this api via dashboard. It prompt the error {"Status":"Error","Message":"Could not retrieve apps list","Meta":null}

But if I create api2 via dasboard manually . It work normally. I also export api1, and api2 to json file and compare, most of them are the same (except app id…)

For further investigating, I try to create a keys for this api1 (via keys session in dashboard). It promp this error Failed to save new session object to Tyk: Failed to create key: Post http://tyk_gateway:8080/tyk/keys/create: EOF
If I try create key for api2, it also normal

So my guest is that the dashboard ws to create api may missed (or I missed config) something, so even api created, it still miss that and making the generation client app has error.

If there was an elf error then the gateway is panicking - can you share the gateway logs?

This log happen when I try create key with access right is api1

time="Dec 29 09:17:03" level=info msg="Reset quota for key." inbound-key="****3a36" key=quota-58648a2a572bf80001fba725910d72d419b3477b448c8b1126c43a36
2016/12/29 09:17:03 http: panic serving 172.22.0.4:42786: runtime error: invalid memory address or nil pointer dereference
goroutine 277218 [running]:
net/http.(*conn).serve.func1(0xc4205a2780)
        /usr/local/go/src/net/http/server.go:1491 +0x12a
panic(0xcb24a0, 0xc420012050)
        /usr/local/go/src/runtime/panic.go:458 +0x243
main.(*DefaultSessionManager).ResetQuota(0xc422575800, 0xc4226a9fc0, 0x38, 0x0, 0x408f400000000000, 0x408f400000000000, 0x3ff0000000000000, 0x5864dca1, 0xffffffffffffffff, 0x5864c56d, ...)
        /src/github.com/TykTechnologies/tyk/auth_manager.go:110 +0x452
main.createKeyHandler(0x12541e0, 0xc42243d6c0, 0xc4200bd590)
        /src/github.com/TykTechnologies/tyk/api.go:1332 +0x28cd
main.CheckIsAPIOwner.func1(0x12541e0, 0xc42243d6c0, 0xc4200bd590)
        /src/github.com/TykTechnologies/tyk/middleware_api_security_handler.go:24 +0x2ae
net/http.HandlerFunc.ServeHTTP(0xc4225ae640, 0x12541e0, 0xc42243d6c0, 0xc4200bd590)
        /usr/local/go/src/net/http/server.go:1726 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc42183f950, 0x12541e0, 0xc42243d6c0, 0xc4200bd590)
        /src/github.com/gorilla/mux/mux.go:114 +0x10d
net/http.(*ServeMux).ServeHTTP(0xc4212fc060, 0x12541e0, 0xc42243d6c0, 0xc4200bd3b0)
        /usr/local/go/src/net/http/server.go:2022 +0x7f
net/http.serverHandler.ServeHTTP(0xc420aa9180, 0x12541e0, 0xc42243d6c0, 0xc4200bd3b0)
        /usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc4205a2780, 0x1255120, 0xc4226a9580)
        /usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2293 +0x44d

This log happen when I click oauth clients in api1

2016/12/29 09:18:22 http: panic serving 172.22.0.4:42790: runtime error: invalid memory address or nil pointer dereference
goroutine 279331 [running]:
net/http.(*conn).serve.func1(0xc42106c900)
        /usr/local/go/src/net/http/server.go:1491 +0x12a
panic(0xcb24a0, 0xc420012050)
        /usr/local/go/src/runtime/panic.go:458 +0x243
main.getOauthClients(0xc421bce2d7, 0x20, 0xd9cdf5, 0x3, 0xc4208bee01, 0x1)
        /src/github.com/TykTechnologies/tyk/api.go:1851 +0x78
main.oAuthClientHandler(0x12541e0, 0xc4232d21a0, 0xc4233e63c0)
        /src/github.com/TykTechnologies/tyk/api.go:1690 +0x25b
main.CheckIsAPIOwner.func1(0x12541e0, 0xc4232d21a0, 0xc4233e63c0)
        /src/github.com/TykTechnologies/tyk/middleware_api_security_handler.go:24 +0x2ae
net/http.HandlerFunc.ServeHTTP(0xc421df08a0, 0x12541e0, 0xc4232d21a0, 0xc4233e63c0)
        /usr/local/go/src/net/http/server.go:1726 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc42183f950, 0x12541e0, 0xc4232d21a0, 0xc4233e63c0)
        /src/github.com/gorilla/mux/mux.go:114 +0x10d
net/http.(*ServeMux).ServeHTTP(0xc4212fc060, 0x12541e0, 0xc4232d21a0, 0xc4233e61e0)
        /usr/local/go/src/net/http/server.go:2022 +0x7f
net/http.serverHandler.ServeHTTP(0xc420aa9180, 0x12541e0, 0xc4232d21a0, 0xc4233e61e0)
        /usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc42106c900, 0x1255120, 0xc421bce280)
        /usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2293 +0x44d

This normal log when I click to “oauth clients” for api2

time="Dec 29 09:19:13" level=info msg="Retrieved OAuth client list" apiID=c5380c5998a1455e625993f3c32ddd07 status=ok

It could be that the APi that you created for API1 is not loaded in the gateway, and so you get this panic - we’ll log it as a bug to prevent the panic, but I’d suggest looking at the log files from when the gateway starts up (restart the process), it will try and load all your API definitions and set up the routing table. If it is bouncing an API configuration because of a configuration error, it will let you know in the output.

hmm I just restart all services.
in gateway logs I can see that i load duplicated many times, my api1 is Authentication (path /auth/)
And also the default portal api, also duplicated. Is this consider normal?

time="Dec 29 09:59:19" level=info msg="Detected 11 APIs"
time="Dec 29 09:59:19" level=info msg="Loading API configurations."
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name="Portal Assets" domain=www.tyk-portal-test.com
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name="Portal API" domain=www.tyk-portal-test.com
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name=ParcelCRUD domain="(no host)"
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name=Portal domain=www.tyk-portal-test.com
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name=ParcelCRUD domain="(no host)"
time="Dec 29 09:59:19" level=info msg="Tracking hostname" api_name=Authentication domain="(no host)"
time="Dec 29 09:59:19" level=info msg="Loading API" api_name="Portal Assets"
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal-assets/" api_id=9dab9825aff7402a781148b10b484d47 org_id=586487584999ef0001d23178
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name="Portal Assets"
time="Dec 29 09:59:19" level=info msg="Loading API" api_name="Portal Assets"
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal-assets/" api_id=c8bc41bbae2e41e04867c6a7a416710d org_id=58648a2a572bf80001fba725
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name="Portal Assets"
time="Dec 29 09:59:19" level=info msg="Loading API" api_name="Portal API"
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal-api/" api_id=c21d5314334f496f69dc9f19b39f2c76 org_id=586487584999ef0001d23178
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name="Portal API"
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=Portal
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal/" api_id=057269ff65ee4bb26815040b92221184 org_id=58648a2a572bf80001fba725
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name=Portal
time="Dec 29 09:59:19" level=info msg="Loading API" api_name="Portal API"
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal-api/" api_id=1b8c1222886f4c5b5f9d430dbe98a4bc org_id=58648a2a572bf80001fba725
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name="Portal API"
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=ParcelCRUD
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=ParcelCRUD
time="Dec 29 09:59:19" level=error msg="Failed to load Middleware JS: open /opt/tyk-gateway/middleware/organization_fetcher.js: no such file or directory"
time="Dec 29 09:59:19" level=info msg="Checking security policy: OAuth" api_name=ParcelCRUD
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=Authentication
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: /auth/" api_id=0c035aa5fe3242fc4c77ccd8badb29ee org_id=58648a2a572bf80001fba725
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name=Authentication
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=Portal
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: www.tyk-portal-test.com/portal/" api_id=3b392886d528470b577bde5c6ff5456f org_id=586487584999ef0001d23178
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name=Portal
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=Authentication
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: /auth/" api_id=baa82f5981be44076b78dd7165f46b8a org_id=5863766026ec0a00019bced6
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name=Authentication
time="Dec 29 09:59:19" level=info msg="Loading API" api_name=Authentication
time="Dec 29 09:59:19" level=error msg="Listen path is a duplicate: /auth/" api_id=baa82f5981be44076b78dd7165f46b8a org_id=586487584999ef0001d23178
time="Dec 29 09:59:19" level=warning msg="Skipped!" api_name=Authentication

No config got big error :frowning:

did yu run the bootstrap script loads of times? Your setup hs many entries with portal proxies - which indicates this is a docker QuickStart.

Second, you have many apis that have the same listen path (/auth) - they will be bounced and not loaded because they interfere with the muxer. That will be what causes the panic. You have api configurations that the gateway cannot load.

Suggest you delete your mongo DB and start with one single config - one org and one user, then try again. Basically the gateway can’t perform operations on apis that are not loaded and the reason it hasn’t loaded them is because they are all sharing a listen path and there’s no way to differentiate them. The issues are all there in the log.

(Edited: typos)

Hi, I try to reinstall everything and its ok now. The problem could be many time trying do something silly