Search code examples
javascriptgoogle-apigoogle-oauthgoogle-api-js-client

Is having the client id and client secret in code a security risk?


I'm using google calendar API to add the event to calendar. I was wondering if it would be security issue as I'm using client Id and API code in JS which can be exposed to someone using the application? Also, if it is the case how to secure those keys?

PS- Docs that I'm following- https://developers.google.com/calendar/quickstart/js


Solution

  • Have you noticed the redirect uri? THe redirect uri tells googles auth server where to return the access token.

    Even if I grab your client id and client secret. I cant use it because the server is going to send the access token to the redirect uri to your server.

    This is why you should not set localhost as a redirect uri. 😉

    RFC oauth2 redirection endpoint

    After completing its interaction with the resource owner, the authorization server directs the resource owner's user-agent back to the client. The authorization server redirects the user-agent to the client's redirection endpoint previously established with the authorization server during the client registration process or when making the authorization request.

    That being said you should try to keep these keys private you should not share them or add them to open source projects. However Client sided applications like javascript is a gray area.