dorisdong0514 2016-10-21 14:21
浏览 37

以编程方式使用Google+帐户登录

there is a service where one can authorize using their Google account. I need to automate the workflow with that service, so my software has to log-in with a given Google account. But as I've never done that before I don't know where to start. Most related answers suggest to display the authorization page to the user letting them to enter their login/password of their Google account, but that's not the case since my software must be fully automated, plus it is being ran in terminal mode so no browser neither any human to enter anything should be involved.

I wonder if such automation could be possible and where should I start.

  • 写回答

1条回答 默认 最新

  • duanjucong3124 2016-10-21 17:35
    关注

    The standard way to authenticate a user with google is through a three-legged oauth authentication flow (in a browser). You can do this in go using the oauth2 or with a more comprehensive package like goth

    The general flow is:

    1. redirect user to a landing page on google's site where they are prompted to grant you access.
    2. google will make a callback to your site with a special code.
    3. you make another request to exchange that code for an access token and a refresh token.
    4. Use access token to use google apis, and use refresh token to get a new access token anytime it expires.

    It is more detailed than this, and there is a lot to get right to keep it secure, but that is the general idea.

    Now, like you've said, your app is a command line thing, so it is hard to do that flow. Unfortunately, you may need to do that once, just to get a refresh token. Once you have that, you could give it to your application: myapp -google-token=FOOBAR123, and your app can exchange the referesh token for a valid access token.

    Maybe this will help: https://github.com/burnash/gspread/wiki/How-to-get-OAuth-access-token-in-console%3F

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题