GithubHelp home page GithubHelp logo

emiliablasten / auth-source-xoauth2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ccrusius/auth-source-xoauth2

0.0 0.0 0.0 61 KB

A package that adds XOAuth2 capabilities to Emacs' auth-source infrastructure

License: Apache License 2.0

Emacs Lisp 79.73% Go 15.86% Makefile 4.42%

auth-source-xoauth2's Introduction

auth-source-xoauth2

http://melpa.org/packages/auth-source-xoauth2-badge.svg

This package adds XOAuth2 authentication capabilities to auth-source.

This integration requires some preliminary work on the users’ part, which includes creating tokens that the package will use. For more details,

M-x describe-variable auth-source-xoauth2-creds

Once all tokens are obtained, adding

(auth-source-xoauth2-enable)

to your configuration will enable XOAuth2 mechanisms in both IMAP and SMTP. For more details, see

M-x describe-function auth-source-xoauth2-enable

If you want to use the package with other services, the auth-source-xoauth2-enable function will probably have to be modified to add the necessary protocol compatibility hooks: the existing contents should serve as a guide, and I would be happy to include contributions in this package.

Note: This package does work with Emacs 25.1, even though it requires 26.1 in the package description. That requirement is necessary in order to silence linter errors. If using Emacs 25.1, the auth-source-pass package is optional.

Debugging

If things are not working, the first thing to do is probably to try and get an access token manually. This can be done with curl as follows (replace the values with your particular ones, and remember to quote whatever needs quoting):

curl --request POST \
  --url 'https://oauth2.googleapis.com/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=refresh_token \
  --data 'client_id=<client_id>' \
  --data 'client_secret=<client_secret>' \
  --data 'refresh_token=<refresh_token>'

This should get you a reply that includes the access token. If it doesn’t, failures will hopefully include error messages that tell you what to do. In the following case, you need to re-generate the refresh token:

{
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}

Obtaining Google (GMail) Tokens

This is a copy & paste of the Elisp documentation for the auth-source-xoauth2-creds variable, which may be more up-to-date than this copy.

If you are using this package to authenticate to Google, the values needed for the auth-source-xoauth2-creds variable can be obtained through the following procedure (note that Google changes this procedure every now and then, so the steps may be slightly different):

  1. Go to the developer console, https://console.developers.google.com/project
  2. Create a new project (if necessary), and select it once created.
  3. Select “APIs & Services” from the navigation menu.
  4. Select “Credentials”.
  5. Create new credentials of type “OAuth Client ID”.
  6. Choose application type “Other”.
  7. Choose a name for the client.

This should get you all the values but for the refresh token. For that one:

  1. Install the Go development tools (from https://go.dev).
  2. Clone the https://github.com/ccrusius/auth-source-xoauth2 repository.
  3. Execute the following command in the cloned repository:
    cd google-oauth
    make
    ./oauth -client_id <client id from previous steps> \
            -client_secret <client secret from previous steps>
        
  4. Visit the URL the tool will print on the console. The page will ask you for the permissions needed to access your Google acount.
  5. Once you give approval, the refresh token will be printed by the tool in the terminal. You should now have all the required values (the :token-url value should be ”https://accounts.google.com/o/oauth2/token”).”)

auth-source-xoauth2's People

Contributors

ccrusius avatar matta avatar darkfeline avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.