# global imports
import sys
import time
+from urllib.parse import urlparse, parse_qs
import requests
from fake_useragent import UserAgent
self.write_log("Downloading: " + url)
res = self.get(url, headers=self.headers)
res.raise_for_status()
+
+ url = f"https://ident.familysearch.org/cis-web/oauth2/v3/authorization?response_type=code&scope=openid profile email qualifies_for_affiliate_account country&client_id=a02j000000KTRjpAAH&redirect_uri=https://misbach.github.io/fs-auth/index_raw.html&username={self.username}"
+ self.write_log("Downloading: " + url)
+ response = self.get(url, allow_redirects=False, headers=self.headers)
+ location = response.headers["location"]
+ code = parse_qs(urlparse(location).query).get("code")
+ url = "https://ident.familysearch.org/cis-web/oauth2/v3/token"
+ self.write_log("Downloading: " + url)
+ res = self.post(
+ url,
+ data={
+ "grant_type": "authorization_code",
+ "client_id": "a02j000000KTRjpAAH",
+ "code": code,
+ "redirect_uri": "https://misbach.github.io/fs-auth/index_raw.html",
+ },
+ headers=self.headers,
+ )
+
+ try:
+ data = res.json()
+ except ValueError:
+ self.write_log("Invalid auth request")
+ continue
+
+ if "access_token" not in data:
+ self.write_log(res.text)
+ continue
+ access_token = data["access_token"]
+ self.headers.update({"Authorization": f"Bearer {access_token}"})
+
except requests.exceptions.ReadTimeout:
self.write_log("Read timed out")
continue