mirror of
https://github.com/j93es/browser-use-oauth.git
synced 2026-06-04 04:01:51 +09:00
Add function to read sensitive data from .sensitive.json file
- Implemented GetSensitiveData function to load sensitive data from a JSON file. - Added error handling for missing file scenario.
This commit is contained in:
parent
29d91bac56
commit
1b65693ba5
6 changed files with 77 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -12,6 +12,7 @@ oauth_providers.csv
|
|||
.venv
|
||||
|
||||
.env
|
||||
.sensitive.json
|
||||
log_*.log
|
||||
|
||||
domains.txt
|
||||
|
|
|
|||
10
.sensitive.example.json
Normal file
10
.sensitive.example.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"*.google.com": {
|
||||
"x_username": "bot.imnya.ng@gmail.com",
|
||||
"x_password": "some.google.password"
|
||||
},
|
||||
"github.com": {
|
||||
"x_username": "imnyang-bot",
|
||||
"x_password": "some.github.password"
|
||||
}
|
||||
}
|
||||
60
README.md
60
README.md
|
|
@ -1,14 +1,13 @@
|
|||
# 참고하면 좋을만한 것
|
||||
|
||||
- [ ] 일부 웹사이트는 사용자의 언어에 따라 OAuth 옵션을 바꾸기도 합니다.
|
||||
- [ ] https://docs.browser-use.com/customize/custom-functions
|
||||
|
||||
# 환경 설정
|
||||
|
||||
이 프로젝트는 [uv](https://docs.astral.sh/uv/getting-started/installation/)라는 Python 패키지 관리자를 사용하여 설정해야합니다.
|
||||
요구 사항
|
||||
- [uv](https://docs.astral.sh/uv/getting-started/installation/) - Python Package Manager Written by Rust
|
||||
- [oauth-backend](https://github.com/j93es/oauth-backend)
|
||||
- [Google Chrome](https://www.google.com/intl/ko_kr/chrome/)
|
||||
|
||||
또한 [oauth-backend](https://github.com/j93es/oauth-backend)가 설정되길 권장합니다.
|
||||
> 프록시를 사용한다면 이 가이드에 따라 인증서 또한 설정되어야만 합니다.
|
||||
---
|
||||
|
||||
> [oauth-backend](https://github.com/j93es/oauth-backend) 프록시를 사용한다면 이 가이드에 따라 인증서 또한 설정되어야만 합니다.
|
||||
>
|
||||
> 그렇지 않으면 실행되지 않습니다.
|
||||
>
|
||||
|
|
@ -31,11 +30,18 @@ uv sync
|
|||
|
||||
venv와 패키지가 설치가 됩니다.
|
||||
|
||||
---
|
||||
|
||||
~~browser_use가 Playwright에 대한 의존성이 있어 브라우저 설치가 필요합니다~~
|
||||
|
||||
스텔스 기능 때문에 Chrome이 필요합니다.
|
||||
스텔스 기능 때문에 Google Chrome이 필요합니다.
|
||||
|
||||
만약 설치가 되어 있지 않다면
|
||||
```
|
||||
playwright install chrome
|
||||
```
|
||||
|
||||
---
|
||||
다음과 같은 명령어로 실행합니다.
|
||||
|
||||
```sh
|
||||
|
|
@ -46,26 +52,50 @@ Environment는 .env.example에 따라 설정되어야합니다.
|
|||
|
||||
.env.example을 .env로 복사하여서 사용해주세요.
|
||||
|
||||
# 쿠키와 로컬 스토리지 설정 방법
|
||||
# 로그인 방안
|
||||
|
||||
## 쿠키와 로컬 스토리지 설정 방법 (추천)
|
||||
|
||||

|
||||
|
||||
```sh
|
||||
uv run playwright open https://google.com/ --save-storage=./data/storage_state.json
|
||||
```
|
||||
|
||||
위 명령어를 실행하면 playwright Browser가 하나 열리는데 여기서 원하는 프로바이더를 모두 로그인 한 후에 브라우저를 정상적으로 닫으면 ./data/storage_state.json 경로에 쿠키, 로컬스토리지를 저장한 파일이 생성됩니다.
|
||||
|
||||
## Browser Use에게 직접 로그인 요청
|
||||
<details>
|
||||
위에 쿠키와 로컬스토리지 설정 방법과 혼용해서 사용가능합니다.
|
||||
|
||||
`.sensitive.example.json`을 `.sensitive.json`으로 복사해서
|
||||
|
||||
안에 있는 예시 내용을 참고해서 작성해주시면 됩니다.
|
||||
|
||||
[Sensitive Data - Browser Use](https://docs.browser-use.com/customize/sensitive-data)에서도 권장하지 않는 방법인만큼 애매하긴 하지만 쿠키와 로컬 스토리지를 저장하기 어려운 경우나 일부 flow에서 접근이 어려운 경우 사용해주세요.
|
||||
</details>
|
||||
|
||||
|
||||
# 실행
|
||||
|
||||
```sh
|
||||
# domains.txt 받기
|
||||
curl "https://f.imnya.ng/.whs/tp-domains/data/domains/latest.txt" -o domains.txt
|
||||
domains.txt는 실행시 자동으로 다운로드 됩니다.
|
||||
|
||||
```sh
|
||||
curl "https://f.imnya.ng/.whs/tp-domains/data/domains/latest.txt" -o domains.txt
|
||||
```
|
||||
|
||||
```sh
|
||||
# ./run.sh {domains.txt 시작 줄} {domains.txt 끝 줄} {HTML 검사 Skip}
|
||||
./run.sh 12540 13000 False
|
||||
```
|
||||
|
||||
|
||||
```pwsh
|
||||
# domains.txt 받기
|
||||
curl "https://f.imnya.ng/.whs/tp-domains/data/domains/latest.txt" -o domains.txt
|
||||
# ./run.ps1 {domains.txt 시작 줄} {domains.txt 끝 줄} {HTML 검사 Skip}
|
||||
./run.ps1 12540 13000 False
|
||||
```
|
||||
|
||||
# 참고하면 좋을만한 것
|
||||
|
||||
- [ ] 일부 웹사이트는 사용자의 언어에 따라 OAuth 옵션을 바꾸기도 합니다.
|
||||
- [ ] https://docs.browser-use.com/customize/custom-functions
|
||||
|
|
|
|||
BIN
docs/image.png
Normal file
BIN
docs/image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
21
lib/utils/browser_use/sensitive_data.py
Normal file
21
lib/utils/browser_use/sensitive_data.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# read json file .sensitive.json
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
def GetSensitiveData():
|
||||
"""
|
||||
Reads sensitive data from a .sensitive.json file in the current directory.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the sensitive data.
|
||||
"""
|
||||
file_path = os.path.join(os.getcwd(), '.sensitive.json')
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
raise FileNotFoundError(f"The file {file_path} does not exist.")
|
||||
|
||||
with open(file_path, 'r') as file:
|
||||
sensitive_data = json.load(file)
|
||||
|
||||
return sensitive_data
|
||||
2
main.py
2
main.py
|
|
@ -20,6 +20,7 @@ from lib.utils.backend_client import notify_backend
|
|||
from lib.utils.browser_use import model
|
||||
from lib.utils.browser_use.clean_resources import clean_resources
|
||||
from lib.utils.browser_use.func import setup_storage_state
|
||||
from lib.utils.browser_use.sensitive_data import GetSensitiveData
|
||||
from lib.utils.config import BACKEND_URL, GOOGLE_MODEL, GOOGLE_PLANNER_MODEL
|
||||
from lib.utils.is_html import is_html_url
|
||||
from lib.utils.read_txt import read_lines_between
|
||||
|
|
@ -114,6 +115,7 @@ async def scan_one_url(url: str, skip_html_check: bool = False):
|
|||
agent = Agent(
|
||||
browser_session=session,
|
||||
initial_actions=initial_actions,
|
||||
sensitive_data=GetSensitiveData(),
|
||||
task=(
|
||||
"Navigate to the login page, identify all OAuth provider buttons (excluding Passkey), "
|
||||
"and for each one: click the button, follow the full OAuth login flow as far as possible "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue