oauth2cli
oauth2cli copied to clipboard
Add support for non-interactive logins on headless machines
This is an opinionated approach to support non-interactive logins on headless machines. These types of machines do not have access to a browser, and thus need to receive an authorization code as the starting point to successfully complete the regular OAuth 2.0 Authorization Code flow. This PR implements that and therefore resolves #13, not as a fallback, but explicitly. Generally it goes as follows:
- Create a config, with
NonInteractiveset to true - Initiate the
GetTokenprocess, and you'll be prompted with an input - In a separate process, initiate
GetCodeAndConfig, and complete the login flow in the browser. Take note of the printed result, which is a base64 encoded struct, that holds both the authorization code and the usedoauth2.config, which is necessary to successfully exchange the code for a token. - Paste the base64 encoded
OAuth2ConfigAndCode, which is decoded and unmarshalled, after which theoauth.configin the providedoauth2cli.Configis overwritten by theoauth2.configused during the retrieval of the code. - The code is exchanged for a token
Note that the processes can be executed on the same machine (why would you do that? 😄), or on separate machines (the entire goal of this PR).
@int128 let me know what you think!
@int128 any chance you could take a look at this PR? :)