Sunbird-RC / community

Repo to enable discussions, issue tracking & documentation for the Sunbird-RC projects
MIT License
12 stars 22 forks source link

Get Institute API throws 401 error #1020

Open cupendra opened 1 month ago

cupendra commented 1 month ago

Hello, I am trying to access the API from the Postman collection available in the "demo_education_registry" repository. I could invoke all other APIs including generating token for Institute. Set the global variable for access token. I continue to get 401 error.

Is there any setting that I need to enable from the realm_admin portal. Here find the Postman raw console output

GET /api/v1/Institute HTTP/1.1 Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJyajVjN01PUG1EY1JIVF9JWEFUWEI0Y2lhb0IxZHhGU1FPc191NWRFX3JrIn0.eyJleHAiOjE3MTY5OTgyMDcsImlhdCI6MTcxNjk5NzkwNywianRpIjoiNjllODRjMTItZWQ4OS00OGQ2LTkwZTgtM2NlMDA0NzZiOTM1IiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL2VkdWNhdGlvbiIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiJhNDI5MzkxYS05MjAxLTRiNGMtOWQ2MS1hNWFlZDExOTAzZDUiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJyZWdpc3RyeS1mcm9udGVuZCIsInNlc3Npb25fc3RhdGUiOiJlMDg5OTdkNy1iYjA4LTQ0NjEtYjBlOC00NjIwYTIyNWY3NmIiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q6ODA4NiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiSW5zdGl0dXRlIiwiSXNzdWVyIiwiZGVmYXVsdC1yb2xlcy1lZHVjYXRpb24iLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzdmdAZ21haWwuY29tIiwiZW1haWwiOiJzdmdAZ21haWwuY29tIn0.rdajFVrqivjWJvAK2nIAjRFK8tPRQUitbLv6pOE1KTL0jRacsQc-FF45ESmGLwsa9s_G4nnzIo799nlyHdOJVKFqlsjRFbzqCEjuMAFRnOqqC-8f0ic22FqGMgpjWMA-p8Pni8xChb4s5K0VjlzxCIqYOSDg5DI72LXa6tXSRI6vgv5ayPiEM97cEAgCadCeQgSYenscM80Ar_vlNOwWojAHRtvBww4IaVg_9FRLqOn6P_d5siRtPJXmZue_ostt4bUXUTkl6AIx5QawzM6iRqNcd0UnQZJc4vuCpScTS3Bu9kovficnwJBgTHRBoF_8M0cpqfE9en6Y3_eSR-TkLg User-Agent: PostmanRuntime/7.39.0 Accept: / Postman-Token: 3e603a5c-c0ad-4546-85f9-d5f7b6e9b416 Host: localhost:8081 Accept-Encoding: gzip, deflate, br Connection: keep-alive

HTTP/1.1 401 Unauthorized WWW-Authenticate: Bearer error="invalid_token", error_description="Invalid issuer", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1" X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Content-Length: 0 Date: Wed, 29 May 2024 15:55:28 GMT Keep-Alive: timeout=60 Connection: keep-alive

cupendra commented 1 month ago

@tejash-jl any help on this? Tried to the follow the Tech Webinar and stuck with this

tejash-jl commented 1 month ago

can you share the docker-compose file?

cupendra commented 1 month ago

@tejash-jl okay. I am running this from registry-cli with "registry init". Here the content of the docker-compose.yml

version: '2.4'

services: es: image: docker.elastic.co/elasticsearch/elasticsearch:7.17.13 environment:

cupendra commented 1 month ago

@tejash-jl I am stuck here to proceed with trying certificate generation and verification. Any help would be appreciated. From the above I tried by changing the "oauth2_resource_uri" to include education realm instead of sunbird-rc realm. Also, changed "sunbird_sso_realm" parameter to have education realm instead of "sunbird-rc" and "sunbird_sso_url" to http://localhost:8080/auth instead of http://keycloak:8080/auth.

Did a dc force-recreate of registry service, however it still not working and returning the same error Bearer error="invalid_token", error_description="Invalid issuer", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"

Kindly help us to proceed further.

holashchand commented 1 month ago

HI @cupendra Your token is generated from http://localhost:8080/auth so it should be the frontend url in keycloak to set frontend url in keycloak login to keycloak -> education -> realm-settings -> frontend-url http://localhost:8080/auth

Or other way is to use http://keycloak:8080/auth to generate the token

then recreate the registry container and try

cupendra commented 1 month ago

Hi @holashchand Already the frontend-url is set to http://localhost:8080/auth

image

Did not work. I can't generate with http://keycloak:8080/auth as the keycloak is running as a container with in my local pc. It will lead to DNS mapping issue.

Please do let me know if there is another thing that I could try to resolve this. If this works through Postman API, my app can then use the same mechanism to talk to registry.

holashchand commented 1 month ago

Hi @cupendra , This should get resolved after recreating registry container though, we can connect to see the issue further

cupendra commented 1 month ago

@holashchand thanks for your time and availability to connect and check we can connect here to see

https://us05web.zoom.us/j/82956067352?pwd=ZDj88SpHhmBAmtiO0e9riAKSIHyvys.1