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

Sdílet
Vložit
  • čas přidán 5. 09. 2024

Komentáře • 35

  • @michaelsglas
    @michaelsglas Před rokem

    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  Před rokem

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

  • @19frett76
    @19frett76 Před 3 lety +1

    That's awesome. Thank you!

  • @elricho72
    @elricho72 Před 2 lety +1

    Great Video 🙂

  • @dimitarilchev7971
    @dimitarilchev7971 Před 2 lety +1

    It is amazing Thank you!

  • @vardangrigoryan3284
    @vardangrigoryan3284 Před rokem +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  Před rokem +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 Před rokem

      @@yagisanatode Great! Thanks a lot

  • @user-cp8nr4wq5h
    @user-cp8nr4wq5h Před rokem +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  Před rokem

      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.

    • @user-cp8nr4wq5h
      @user-cp8nr4wq5h Před rokem

      ​@@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.

  • @stevensonnwokenkwo3281
    @stevensonnwokenkwo3281 Před 2 lety +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  Před 2 lety

      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 Před 2 lety

      Awesome! Nice to know, thanks...

  • @user-fz3zn8qb1q
    @user-fz3zn8qb1q Před rokem

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

    • @yagisanatode
      @yagisanatode  Před rokem

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

  • @gianfranco2101
    @gianfranco2101 Před 2 lety +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  Před 2 lety

      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.

  • @subarnamainali2347
    @subarnamainali2347 Před 2 lety +1

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

    • @yagisanatode
      @yagisanatode  Před 2 lety

      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 Před 2 lety

      @@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 ?

  • @baizanp
    @baizanp Před 2 lety

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

  • @ahmedawji846
    @ahmedawji846 Před 2 lety

    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  Před 2 lety

      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

  • @perrysantos
    @perrysantos Před 2 lety

    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  Před 2 lety +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 Před 2 lety +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  Před 2 lety +1

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

    • @perrysantos
      @perrysantos Před 2 lety +1

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

  • @michelparmentier3063
    @michelparmentier3063 Před 2 lety

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

    • @yagisanatode
      @yagisanatode  Před 2 lety +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 Před 2 lety +1

      @@yagisanatode Thanks, I will try that !

    • @michelparmentier3063
      @michelparmentier3063 Před 2 lety +1

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