Give permissions to specific users to access a Web App with Google Apps Script

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 35

  • @michaelsglas
    @michaelsglas 2 роки тому

    Thanks you for sharing an educational segment. As being a self taught dev your video has helped me put together a thought that I think I might just be able to build.

    • @yagisanatode
      @yagisanatode  2 роки тому

      Hi Michael. That is really heartwarming to hear. Thank you for the kind words.

  • @Youtep-e5h
    @Youtep-e5h Рік тому +1

    Hello, do you know how to protect a google sheet with a licence ? Or protect the cells formulas, or protect the script ? Thank you dude.

    • @yagisanatode
      @yagisanatode  Рік тому

      This link ( support.google.com/drive/answer/2494893#zippy= ) Talks about how to share files, give certain permissions, prevent others from sharing the file and schedule access to the file.
      You can protect sheet tabs and cells as an editor or owner: yagisanatode.com/google-sheets-beginners-protecting-cells-ranges-and-sheet-tabs-23/
      To protect a script bound to a Google Sheet you will need to publish it as a Google Editor Add-on.

    • @Youtep-e5h
      @Youtep-e5h Рік тому

      ​@@yagisanatode thank you for your answer, me I need to share my sheet to people that will use it, so they need to edit it, but I don't want they copy the formulas or the script... I don't find the way.

  • @vardangrigoryan3284
    @vardangrigoryan3284 Рік тому +1

    Hi, thanks so much for the explanation. I'm a bit confused regarding the actual fileID. Should the fileID be kept hard coded or can we get the fileID of the file from where the doGet() is triggered (for ex., if there is another spreadsheet with a button that triggers the web app URL). If we do the second option (getting the fileID dynamically), would that mean that anybody who has the web app URL would be able to get access to it and be validated?

    • @yagisanatode
      @yagisanatode  Рік тому +1

      You could definitely parse a file ID as an event parameter. It a users has the ability to use a menu item or button in your Google Sheet they will have edit access to that sheet. Validation relies on the getEditors() method of the effective user ( The person attempting to access the WebApp). If their Google credentials do not contain the required permission to access the add-on then they will be redirected to the no access page.

    • @vardangrigoryan3284
      @vardangrigoryan3284 Рік тому

      @@yagisanatode Great! Thanks a lot

  • @baizanp
    @baizanp 2 роки тому

    is it possible that it doesnt recognize me as an editor cause im the Owner of the file?

  • @sandipmaruji
    @sandipmaruji Рік тому

    Great tutorial, how would you go about calling an webApp restricted to a domain. How do you set up the authorization?

    • @yagisanatode
      @yagisanatode  Рік тому

      Hi there, you could validate the effective user against the domain in their email.

  • @gianfranco2101
    @gianfranco2101 3 роки тому +1

    HI. Thanks a lot, very useful. Just when I do the call file = DriveApp.getFileById(fileID); in validate function, the returned value is undefined. I'm sure I have access to the document referenced by the id ? an Idea? Thanks

    • @yagisanatode
      @yagisanatode  3 роки тому

      Hi Gianfranco, that is weird. It's difficult to see what is going on without seeing your code. The only thing I suggest for now is that you double check your variables match and the file ID is correct.

  • @perrysantos
    @perrysantos 3 роки тому

    i have ran this many times, and i cant get to work with individual emails, when i added groups in validation, then it worked. could you try please? take off groups in sharing and test. thanks

    • @yagisanatode
      @yagisanatode  3 роки тому +1

      Hi Perry, Retested the code as requested and it's working as expected my end. It's difficult to see what's going on your side without looking your code and your deployment setup. For the time being you can grab the script from the written tutorial: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/ . If you are still stuck feel free to comment in the written tutorial with your code or send me an email using the contact form from my site with a link to a version of your script. When/If I get a chance I will try and take a look at it.

    • @perrysantos
      @perrysantos 3 роки тому +1

      @@yagisanatode tyvm for you reply, i will try the link you provided, if i get stuck, i will let you know. Can i email you just in case?

    • @yagisanatode
      @yagisanatode  3 роки тому +1

      @@perrysantos Sure you can send me a message here: yagisanatode.com/contact/ . Time permitted I will take a look,

    • @perrysantos
      @perrysantos 2 роки тому +1

      @@yagisanatode my bad.. i just realized this works only within Google Workspace organisation.. sorry to caused a confusion...

  • @19frett76
    @19frett76 3 роки тому +1

    That's awesome. Thank you!

  • @ahmedawji846
    @ahmedawji846 3 роки тому

    Hi thanks for the video, however Im running through a problem, I tried to debug the code through running 'console.log('file editors',file.getEditors()); ' and its returning 'file editors [ {}, {} ]' array of empty objects. Whats the problem?

    • @yagisanatode
      @yagisanatode  3 роки тому

      Hi Ahmed, check out the full written tutorial, it might help you out a bit more: yagisanatode.com/2021/08/18/how-to-validate-specific-users-on-a-web-app-in-google-apps-scripts/
      getEditors() gives you a constructor array of all editors. Each editor in this array has its own methods, one of these is getEmail(). If you say console.log() this:
      ```
      file.getEditors().map(editor => {
      return editor.getEmail();
      })
      })();
      ```
      Then you will get a list of all the editors by email.
      Hope this helps.
      Happy coding.
      ~Yagi

  • @dimitarilchev7971
    @dimitarilchev7971 2 роки тому +1

    It is amazing Thank you!

  • @stevensonnwokenkwo3281
    @stevensonnwokenkwo3281 2 роки тому +1

    Fabulous video! one question; so, what happens when the file is shared to everyone with no specific email, in that case there is no shared list to, would it recognize the validation for any google account holder?

    • @yagisanatode
      @yagisanatode  2 роки тому

      Emails are still referenced by Google in this case, so if you have a list of users you want approved, you will still be good to go.

    • @stevensonnwokenkwo3281
      @stevensonnwokenkwo3281 2 роки тому

      Awesome! Nice to know, thanks...

  • @elricho72
    @elricho72 3 роки тому +1

    Great Video 🙂

  • @michelparmentier3063
    @michelparmentier3063 3 роки тому

    nice ! How do you remove the annoying grey warning bar ?

    • @yagisanatode
      @yagisanatode  3 роки тому +1

      Yeah, it is a bit of a pain but I get why Google is protecting itself. Your best bet is to embed the Web App in a site. The fastest way would be to create a quick and free Google Site at sites.google.com and use the embed tool there. The warning will disappear.

    • @michelparmentier3063
      @michelparmentier3063 3 роки тому +1

      @@yagisanatode Thanks, I will try that !

    • @michelparmentier3063
      @michelparmentier3063 3 роки тому +1

      @@yagisanatode 5 minutes test and it worked, ty !

  • @subarnamainali2347
    @subarnamainali2347 3 роки тому +1

    How to use two html file if user is correct ?
    let htmlfile = (isValid)? 'home' :'NonUser';
    HERE !!!

    • @yagisanatode
      @yagisanatode  3 роки тому

      Hi Subarna, You could use the Javascript Switch method for more than on condition here to allow for two or more correct cases. You would need to return either false if not authorized and then a value for each of your true cases from the validation.

    • @subarnamainali2347
      @subarnamainali2347 3 роки тому

      @@yagisanatode I tried this and if person;s id is authorized it opens home.html & when home redirects to another page it doesn't how to fix it ?