Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CEP google Oauth

Participant ,
Jun 03, 2019 Jun 03, 2019

I have been working CEP that can pull data from a public google sheet.

This works.

I now want, after the data has been retrieved and the script has run to change a cell value so when it goes through the loop. It will skip anything that isn't specified.

This appears to require Oauth, which i've been testing with using a http://localhost . I got this all working really well.

Now importing the code back into my panel. I realised a few things. It's not a localhost.

This isn't being sold and is bespoke for myself and the company I work for, so I don't need a webserver/website to run it off (Or do I?)

How can I get my CEP Panel get passed the Oauth so I can keep my sheets private and use the Google API (Unless anyone else has alternative suggestions)

7.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2019 Jun 18, 2019

Hey Justin,

On the off chance you might've done this before.

Because my plugin has a lot of html pages that does different thing based on brand. I use "href" to switch between pages.

<a href="https://accounts.google.com/o/oauth2/v2/auth?client_id<CLIENT ID>&response_type=code&scope=https://www.googleapis.com/auth/gmail.send&redirect_uri=http://localhost:3200/localServer.html&acces...">Login</a>

If I use the http in my web browser. This automatically signs me into my http://localhost:3200/localSever.html

Now I thought I got this working, but it seemed to be a fluke, as it only happened once and then I messed with it and it didn't happen again.

When I clicked on the href, this asked me to login. I logged in and it sends me to my http://localhost:3200/localSever.html, but unlike my web browser, which signs me in automatically. My CEP window does not.

I'm struggling with the token and the node as it is above me. So I've been trying to find other ways. The CEP Panel is html, it should in theory act like a html, but this


gapi.auth2.getauthinstance().signin()

seems to be the problem. If I could get this to launch a new window and let me authorise. This would be solved.

If you can't, can you think of any other forums that might be able to offer suggestions?

Kind Regards

Scott

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2019 Jun 18, 2019

You can open HTML, pages in your CEP panel, since the panel itself is essentially a Chrome Browser with some limitations, so you can change the location with window.location or create an iframe or something. If you'd rather not have the sign-in page in the same window, then you can make a modal dialog window popup with this page that has it's href set to the login destination.

Once again, I haven't tried any of these methods myself. I simply created a toke with the CLI and then loaded it from there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2019 Jun 18, 2019

Hey Justin,

I really do appreciate your responses. Totally understand that you've not done these before, but you've gotten me closer from guesswork than anyone else.

I don't mind it being in the same page, it's just that the

gapi.auth2.getauthinstance().signin()

Does nothing in the CEP, but launches in web browser. Which I don't understand, I know it's probably something stupid like using CSInterface.

If I can get it to launch in the same window, take me away from my index page and return once signed in would be fantastic, but I just want it to launch the sign in page when I hit sign in, I can figure the rest out after that.

How would you launch the sign in into an iframe? That sounds like the perfect solution.

This is the last piece as far as I'm aware haha.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2019 Jun 18, 2019

Does gapi.auth2.getauthinstance().signin() launch a web page on its own? If so, then I don't think you can use an iframe. If it can return a url of some sort, then you can load that into an iframe and go from there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2019 Jun 18, 2019

It opens a popup window, but this does have a url if you hover over it.

So I'm assuming part of it opens a new window with the http:// and content preloaded client ID etc similar to my "href" example.

I don't have my machine in front of me, but I do know that I spotted it had a url when hovering, that's what made me try href

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 19, 2019 Jun 19, 2019

Hey Justin,

Hopefully this is the one.

I've figured out how to get my token, that was actually easier than I thought.

Preconfigured link that returns my google code 4/bldfnaksjbdfgoajbjbaouborve;jasdvpobad (I've made this up)

Then I use $.Ajax to create my token.

The next part is reading the token

fs.readFile(TOKEN_PATH, (err, token) => {

if (err) return getAccessToken(oAuth2Client, callback);

oAuth2Client.setCredentials(JSON.parse(token));

callback(oAuth2Client);

});

}

Can this only be done via node? fs.readFile appears to be the only way that I can find info on.

This is the last part I'm struggling with, then I should be in.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2019 Jun 19, 2019

Glad to hear you found some solutions to that! You're past the hard part, the rest is easy.

You can read files in a variety of ways, my favorite is

var contents = fs.readFileSync(path, 'utf8');

and then you'll want to parse that token file

var token = JSON.parse(contents)

There are also some built-in read methods in CEP like cep.fs.readFile(), but they seem less reliable, I'd stick with the Node.js methods.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 19, 2019 Jun 19, 2019

With your setup, how do you layout the node?

I'm just wondering if the above link that I shared that shows you how to set it up has thrown me off finding probably an easier setup.

Root -
          CXCS - Manifest
          Client - index.html
                       index.js

                       CSInterface.js

                       localServer.html (Launches Node)

          server - main.js (node)

          host - index.jsx

package.json

package-lock.json

token.json

I need to play with the node more, the demo gives a vague setup for PS, yet I use AE. I could do with a basic guide and play around with it.

I've found issues for it writing into the root folder, but I could be doing things wrong, because of this demo I've worked off.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2019 Jun 19, 2019

You can structure however you like, so long as the manifest is in the CSXS folder, and proper links are maintained from there. Best to only keep constant files in your extension directory, and store your token in a user data or documents folder since that's subject to change.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 20, 2019 Jun 20, 2019

Justin,

I have a nearly fully working prototype. No Token needed and I'll share the code shortly, just making sure all bugs are fixed.

I discovered ux_mode for redirecting in the browser. This allowed me to authenticate my CEP and redirect back to my node localServer which now can interact with AE.

A bit of trial and error, but my Plugin will duplicate my Master Comp, update it per row/column. Just getting the .update tidied up and that should be it as a basis to build.

You still need node, but you don't need to worry about logging in every time as that browser has been authenticated (Don't know about switching my machine off and on, but AE off and on still keeps it logged in until you hit the sign out button). Nor do you need a token.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2019 Jun 29, 2019
LATEST

This week I found myself needing to use OAuth for the GitHub API (similar workflow). The solution was similar to yours:

- Start an http server (or use an existing one)

- Sending an http request to authenticate

- Open the response URL in an external browser

- After user authentication, make sure the redirect_uri is set to the localhost port of your server

- User is sent back to your server with the token key in the address field which you can get from your server request message

- Then simply serve a script that auto-closes the authentication window

- Save the token on disk for perpetual authentication

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines