Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saadmairaj/oauthbrowser
This module will let you authenticate OAuth 2.0 via the system browser and get the response URL.
https://github.com/saadmairaj/oauthbrowser
applescript authentication google oauth2 osascript scraping-python url webscraping
Last synced: about 8 hours ago
JSON representation
This module will let you authenticate OAuth 2.0 via the system browser and get the response URL.
- Host: GitHub
- URL: https://github.com/saadmairaj/oauthbrowser
- Owner: Saadmairaj
- License: mit
- Created: 2020-04-30T21:49:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-20T04:29:55.000Z (over 1 year ago)
- Last Synced: 2024-08-08T15:28:10.976Z (3 months ago)
- Topics: applescript, authentication, google, oauth2, osascript, scraping-python, url, webscraping
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# OAuthBrowser
[![PyPI](https://img.shields.io/pypi/v/OAuthBrowser)](https://pypi.org/project/oauthbrowser)
[![Maintainability](https://api.codeclimate.com/v1/badges/5e6ea349636a097fdae1/maintainability)](https://codeclimate.com/github/Saadmairaj/OAuthBrowser/maintainability)
[![Downloads](https://pepy.tech/badge/oauthbrowser)](https://pepy.tech/project/oauthbrowser)
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FSaadmairaj%2FOAuthBrowser&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)This module will let you authenticate [OAuth 2.0](https://oauth.net/2/) via system browser and get response URL. Currently supporting **Google Chrome** and **Safari** browsers. Built with *applescript* and [*osascript*](https://ss64.com/osx/osascript.html), only works on Mac OSX.
A lot more can be done with **OAuthBrowser** like getting source code without getting automation detection from websites.
## Installation
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install [OAuthBrowser](https://pypi.org/project/OAuthBrowser/).
```bash
pip install OAuthBrowser
```Or install the latest repo from here.
```bash
pip install git+https://github.com/Saadmairaj/OAuthBrowser#egg=OAuthBrowser
```## Usage
Usage is very simple
1. Pass authentication URL.
2. Apply `Wait` class to wait for the browser to redirect.
3. Fetch URL.
4. Close browser.```python
from OAuthBrowser import Safari, Wait
from urllib.parse import urlparse, parse_qsURL = """https://accounts.google.com/signin/oauth/oauthchooseaccount?
scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&
state=state_parameter_passthrough_value&
redirect_uri=https%3A%2F%2Foauth2.example.com%2Fcode&
access_type=offline&
response_type=code&
client_id=583306224539-atbcaa8ne8g85e8kc006o6vmq99qiid0.apps.googleusercontent.com&
o2v=2&as=CDdm3G6Zd1UOG9o_gWXzQQ&flowName=GeneralOAuthFlow"""# Initialise browser
browser = Safari(window_geometry=(100, 22, 400, 690))
# Pass Authentication URL
browser.open_new_window(URL)
# Initialise Wait
wait = Wait(browser)
# Wait till query "code" is present in the URL.
wait.until_present_query('code')
# Fetch the url
response_url = urlparse(browser.get_current_url())
code = parse_qs(response_url.query).get('code')[0]
print("\nCode: %s\n" % code)
# Close the browser
browser.quit()
```## Demonstration
```bash
python -m OAuthBrowser
```## Contributing
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method of this repository before making a change.
Please make sure to update tests as appropriate.
## License
[MIT](https://github.com/Saadmairaj/OAuthBrowser/blob/master/LICENSE.txt)