How to implement oauth for google login from CEF?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to implement oauth for google login from CEF?

Postby rjxray » Tue Mar 17, 2020 9:04 am

I really need to be able to do this now.
There are guidelines at https://developers.google.com/identity/ ... native-app
Has anyone made any progress at all with this?
rjxray
Mentor
 
Posts: 51
Joined: Wed Jun 07, 2017 4:31 am

Re: How to implement oauth for google login from CEF?

Postby salvadordf » Tue Mar 17, 2020 10:24 am

We have a demo in the CEF4Delphi project called "OAuth2Tester" that uses CEF to get the OAuth2 access token.

Then you can use the token in the requests to the Google REST APIs but I couldn't find a way to identify the users in regular browser requests. Adding an "Authorization" HTTP header didn't work for normal browsing.
Maintainer of the CEF4Delphi project.
User avatar
salvadordf
Expert
 
Posts: 106
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: How to implement oauth for google login from CEF?

Postby rjxray » Tue Mar 17, 2020 12:05 pm

We have a demo in the CEF4Delphi project

Is the code available to help me get started?
rjxray
Mentor
 
Posts: 51
Joined: Wed Jun 07, 2017 4:31 am

Re: How to implement oauth for google login from CEF?

Postby salvadordf » Tue Mar 17, 2020 12:57 pm

Yes but it uses Pascal, not C/C++, and it uses the CEF4Delphi components.

The Delphi version of that demo is here :
https://github.com/salvadordf/CEF4Delph ... uth2Tester

And the Lazarus/FPC version is here :
https://github.com/salvadordf/CEF4Delph ... uth2Tester

Read the code comments in the *.pas files

That demo uses this unit that may interest you :
https://github.com/salvadordf/CEF4Delph ... Helper.pas
Maintainer of the CEF4Delphi project.
User avatar
salvadordf
Expert
 
Posts: 106
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain

Re: How to implement oauth for google login from CEF?

Postby rjxray » Wed Mar 18, 2020 4:18 am

Thanks, I'll have a good look.
rjxray
Mentor
 
Posts: 51
Joined: Wed Jun 07, 2017 4:31 am

Re: How to implement oauth for google login from CEF?

Postby rjxray » Thu Apr 30, 2020 6:01 am

So thanks to @salvadordf and https://github.com/googlesamples/oauth- ... r-windows/ (C#), I managed to get OAuth2 credentials with C++/CEF/OpenFrameworks/Visual Studio/Windows 10.
See attached rather rough and ready code which could easily be adapted to any windows cef app.
I haven't yet tried exchanging the refresh token but it should be straightforward now.

Instead, I've tried using the access token with a browser but like @salvadordf I'm unable to make it work.
Here's how I tried:

Code: Select all
void MyBrowser::authload(string url, string token) {
   CefRefPtr<CefFrame> frame = browser_->GetMainFrame();
   CefRefPtr<CefRequest> request = CefRequest::Create();
   request->SetMethod("GET");
   request->SetURL(url);
   CefRequest::HeaderMap headerMap;
   headerMap.insert(std::make_pair("Authorization", "Bearer%20" + token));
   request->SetHeaderMap(headerMap);
   frame->LoadRequest(request);
}

Using a url which is a shareable link to a presentation on my company's google drive and an access token resulting from an OAuth2 login to my company account I still get asked for user and password.
I've tried several different variants and nothing works.

After a lot of research I'm coming to the conclusion that I can only use the token with direct requests to google API's .
Am I right, or can anyone suggest another way?

I guess that using the google drive API I could download the presentation and open it locally with a CEF browser but I haven't tried going down that rabbit hole yet.
Particularly as to make it work in the real world we would have to submit my app to google for review at a cost of at least $15000 and I have a feeling they may reject this usage.
See https://support.google.com/cloud/answer/9110914
Attachments
oAuthLogin.cpp
(10.2 KiB) Downloaded 202 times
oAuthLogin.h
(3.53 KiB) Downloaded 175 times
rjxray
Mentor
 
Posts: 51
Joined: Wed Jun 07, 2017 4:31 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 7 guests