0

I'm getting below error when trying to create a google event from anypoint studio using google connector.

OAuth authorization dance not yet performed for resourceOwnerId null

Basically to test this functionality, I did below

  1. I took a listener connector (path:/hello) and configured with local host 8081
  2. Dragged google calendar event insert connector and configured with below details
    1. Base url: https://www.googleapis.com/calendar/v3
    2. consumer secret : Entered corporate clent id
    3. Consumer secret:Entered secret key
    4. Authorization url : https://accounts.google.com/o/oauth2/auth
    5. Access token url : https://accounts.google.com/o/oauth2/token
    6. Scopes: https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events https://www.googleapis.com/auth/calendar.events.readonly https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/calendar.settings.readonly
    7. Call back path : /oauth2callback
    8. Authorize path : /authorize
    9. external callback url : http://localhost:8081/oauth2callback

I left remaining below fields empty in the google calendar connecter.

  1. Resource Owner id
  2. Before
  3. after
  4. Object store

In between, HTTP Listener and Google calendar events Insert connecter, I placed Transform message and written below Dataweave

%dw 2.0
output application/json
---
{
    summary: payload.summary,
    start: {
        dateTime: payload.start.dateTime,
        timeZone: payload.start.timeZone
    },
    end: {
        dateTime: payload.end.dateTime,
        timeZone: payload.end.timeZone
    }
}

Below is the JSON input I'm giving from the postman, url being http://localhost:8081/hello

{
   "end": {
        "datetime": "2022-05-19T16:00:00+05:30",
        "timezone":Asia/Chennai
    },
    "start": {
        "datetime": "2022-05-19T14:00:00+05:30",
        "timezone":Asia/Chennai
    },
       "summary":"First PO from Mulesoft Google connector",
       "description":"First desc from Mulesoft Google connector",
       "location":"Hyderabad",
    "attendees":[
         {
             "email":"testmail@email.com"
         }
    ]
}

I'm using anypoint studio 7.8.0.

Thanks in advance.

Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22
GVMK
  • 27
  • 1
  • 1
  • 6

1 Answers1

1

You need to start the OAuth dance first, to get the access token. You can start it by hitting the Authorize path that you have configured in your app, which in your case is http://localhost:8081/authorize

After that you will be redirected to Google sign in page. If the Google oauth credentials are configured correctly the mule app will get the access token and use it for the future requests.

Harshank Bansal
  • 2,798
  • 2
  • 7
  • 22
  • Thank you Harshank, When I tried to start the OAuth dance, it gave me this error : **Error 400: redirect_uri_mismatch.** I registered the URL : http://localhost:8081/authorize in google console but no luck, it gave me the same error. Then I replaced localhost with my IP address and registered, still no luck. it is giving me same error. – GVMK May 23 '22 at 17:04
  • That should be the callback url that you have configured as `External Callback URL` i.e. `http://localhost:8081/oauth2callback` – Harshank Bansal May 23 '22 at 17:26
  • I removed the url : localhost:8081/authorize from google console and registered this url localhost:8081/oauth2callback in google console. Now, when I run the localhost:8081/authorize, it is giving me this error again **Error 400: redirect_uri_mismatch.** – GVMK May 23 '22 at 20:16
  • you added with http and everything, right? Maybe it takes some time to reflect the changes. You can try to check for any typos and maybe there is an extra space somewhere in start or end. – Harshank Bansal May 24 '22 at 17:58
  • yes, I added above url's with http only. – GVMK May 24 '22 at 19:35
  • When I add the callback url with http://localhost:8081/oauth2callback , does google understand the localhost? or it needs to be replaced with IP address? – GVMK May 24 '22 at 21:26
  • It does understand it. If will redirect you to any url, even if it does not exists. You problem is coming even before redirect. I will suggest to look at any tutorial for calendar events (does not have to be mulesoft) and verify your config in Google. – Harshank Bansal May 24 '22 at 21:49
  • Is it possible you are making change in different credentials then the mule one?. You can check some answers here too https://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch – Harshank Bansal May 24 '22 at 21:52
  • At last it worked, I see we have two OAuth's defined in google console, one of the type is Service Account client and another is Desktop. I was always trying Service Account's Client id and secret and it was not working. When I tried Desktop version it started working. later when I tried to change the Service Accounts Client id & Secret it also working now. Thanks @harshank Bansal for your help. – GVMK May 26 '22 at 01:58