Is it possible to use multiple authentications in a Google Apps Script web-app?

后端 未结 1 1144
暖寄归人
暖寄归人 2020-12-18 13:42

I know how to write a web-app and publish it as myself. What I am trying to do is publish a web app so that it can access both my data and the users data.

相关标签:
1条回答
  • 2020-12-18 14:18

    Workaround#1: Two web apps

    Use two web apps and handle authentication between those two:

    • WebApp#1: API to access your sheet

      • Execute as "Me"
      • Access: "Anyone, even anonymous"
      • Handles incoming POST requests: checks for necessary authorizations, authenticates the request and returns data from sheet.
    • WebApp#2: User facing app

      • Execute as "User accessing the web app"
      • Access: "Anyone"
      • User requests data from your sheet> Client requests Server(google.script.run)> Server POSTs request along with necessary authorization headers using UrlFetchApp> receives and parses the sheet data and provides it to client.
    • Notes:

      • This set up security is only as strong as the authorization/authentication used between the web-apps.

    Workaround#2: Client side Google sign in

    • Implement Google signin in your webapp.

      • Execute as "Me"
      • Access: "Anyone, even anonymous"
      • Users accessing the web-app must sign in
      • After signing in and authorizing access to their sheets, you can use sheets api to write to their sheet
    • References:

      • Google sign-in
      • Sample snippet: Sheets api access from browser
      • Related question
    0 讨论(0)
提交回复
热议问题