msa7 / multi_auth

Standardized multi-provider OAuth authentication
MIT License
111 stars 23 forks source link

Missing has: names #2

Closed rishavs closed 7 years ago

rishavs commented 7 years ago

Hi

I tried the example given in the github page. I used it for a google auth process.

However when the redirect_uri is called, i get the following error;

Missing hash key: "names" (KeyError)
0x559ef99d459b: fetch at /opt/crystal/src/hash.cr 124:9
0x559ef99d446d: [] at /opt/crystal/src/hash.cr 60:5
0x559ef99d4ee8: [] at /opt/crystal/src/json/any.cr 100:15
0x559ef999f175: primary? at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/providers/google.cr 68:5
0x559ef999f06d: primary at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/providers/google.cr 62:15
0x559ef999e3dc: build_user at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/providers/google.cr 81:12
0x559ef999e360: user at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/providers/google.cr 59:5
0x559ef999adac: user at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/engine.cr 23:5
0x559ef9867c6c: ~procProc(HTTP::Server::Context, (String | Nil)) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x559ef9869b1c: ~proc4Proc(HTTP::Server::Context, String) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x559ef998326d: process_request at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/route_handler.cr 255:3
0x559ef9983096: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/route_handler.cr 18:7
0x559ef99e5e86: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x559ef99e5859: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/static_file_handler.cr 56:9
0x559ef99e496d: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x559ef99e4450: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/common_exception_handler.cr 9:9
0x559ef99e39f3: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x559ef99e0601: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/common_log_handler.cr 13:35
0x559ef99820e8: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x559ef9981ccf: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/init_handler.cr 11:7
0x559ef99ed80b: process at /opt/crystal/src/http/server/request_processor.cr 39:11
0x559ef99ed119: process at /opt/crystal/src/http/server/request_processor.cr 16:3
0x559ef99e75e0: handle_client at /opt/crystal/src/http/server.cr 191:5
0x559ef986b293: ~procProc(Nil) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x559ef98875ce: run at /opt/crystal/src/fiber.cr 255:3
0x559ef98628a6: ~proc2Proc(Fiber, (IO::FileDescriptor | Nil)) at /opt/crystal/src/concurrent.cr 61:3
0x0: ??? at ??
msa7 commented 7 years ago

Sorry for later response.

Could you please trace and submit here raw_json before line 79 at providers/google.cr

rishavs commented 7 years ago
{
  "error": {
    "code": 403,
    "message": "Google People API has not been used in project kamel-dev before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/people.googleapis.com/overview?project=kamel-dev then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console API activation",
            "url": "https://console.developers.google.com/apis/api/people.googleapis.com/overview?project=kamel-dev"
          }
        ]
      }
    ]
  }
}

I think in case of errors, it will be prudent to show the error message.

EDIT: anfter enabling the api, i am now getting;

invalid_grant: Invalid code. (OAuth2::Error)
0x5597fcf9e43a: get_access_token_using_authorization_code at /opt/crystal/src/oauth2/client.cr 152:7
0x5597fcfa00ab: user at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/providers/google.cr 33:20
0x5597fcf9cdac: user at /home/rick/DevSpace/Crystal/Kamel/lib/multi_auth/src/multi_auth/engine.cr 23:5
0x5597fce69c6c: ~procProc(HTTP::Server::Context, (String | Nil)) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x5597fce6bb1c: ~proc4Proc(HTTP::Server::Context, String) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x5597fcf8526d: process_request at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/route_handler.cr 255:3
0x5597fcf85096: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/route_handler.cr 18:7
0x5597fcfe7e96: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x5597fcfe7869: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/static_file_handler.cr 56:9
0x5597fcfe697d: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x5597fcfe6460: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/common_exception_handler.cr 9:9
0x5597fcfe5a03: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x5597fcfe2611: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/common_log_handler.cr 13:35
0x5597fcf840e8: call_next at /opt/crystal/src/http/server/handler.cr 24:7
0x5597fcf83ccf: call at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/init_handler.cr 11:7
0x5597fcfef81b: process at /opt/crystal/src/http/server/request_processor.cr 39:11
0x5597fcfef129: process at /opt/crystal/src/http/server/request_processor.cr 16:3
0x5597fcfe95f0: handle_client at /opt/crystal/src/http/server.cr 191:5
0x5597fce6d293: ~procProc(Nil) at /home/rick/DevSpace/Crystal/Kamel/lib/kemal/src/kemal/dsl.cr 10:1
0x5597fce895ce: run at /opt/crystal/src/fiber.cr 255:3
0x5597fce648a6: ~proc2Proc(Fiber, (IO::FileDescriptor | Nil)) at /opt/crystal/src/concurrent.cr 61:3
0x0: ??? at ??
msa7 commented 7 years ago

Google error handler added.

invalid_grant: Invalid code. (OAuth2::Error)

I setup new google app, after enabling People API it works. Look like you need fresh code, so do redirect first multi_auth.authorize_uri to get new code