Skip to content

Commit

Permalink
DRAFT: initial commit, non functioning with test script
Browse files Browse the repository at this point in the history
  • Loading branch information
nd4p90x committed Sep 22, 2023
1 parent 1c44a93 commit a411661
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
64 changes: 64 additions & 0 deletions segment/analytics/oath2Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import requests
import os
from urllib.parse import urlencode
import webbrowser

CLIENT_ID = "Iv1.9332e33a45a46e2f"
CLIENT_SECRET = "ddfc4878523bf3e7038f2e72ca0f3900382a95e9"
REDIRECT_URI = "https://httpbin.org/anything"
BASE_API_ENDPOINT = "https://oauth2.segment.build"

"""
Github App
CLIENT_ID = "Iv1.9332e33a45a46e2f"
CLIENT_SECRET = "ddfc4878523bf3e7038f2e72ca0f3900382a95e9"
REDIRECT_URI = "https://httpbin.org/anything"
BASE_API_ENDPOINT = "https://api.github.com/user"
endpoint = "https://github.com/login/oauth/authorize"
AFTER CODE ENDPOINT
endpoint = "https://github.com/login/oauth/access_token"
"""

"""
Here's the key file for OAuth2.
You'll need to specify a different endpoint server, api.segment.build
The write key for the source is TEBWeMLQWxtJjW8B91Hu5bujQLqhpLUR
The Client/App ID: 2TlKP068Khdw4jZaCHuWjXmvui2
The Key ID: 2TlKOw1a7n9tUUmVK1ISKnnJ0hA
"""

params = {
"client_id": CLIENT_ID,
"redirect_uri": REDIRECT_URI,
"scope": "user"
}

endpoint = "https://oauth2.segment.build/login/oauth/authorize"
endpoint = endpoint + '?' + urlencode(params)
webbrowser.open(endpoint)

code = input("Enter the Code: ")

print("Got Code")

params = {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"redirect_uri": REDIRECT_URI,
"code": code,
}
endpoint = "https://oauth2.segment.build/token"
response = requests.post(endpoint, params=params, headers = {"Accept": "application/json"}).json()
access_token = response['access_token']
print("Got Access Token")

session = requests.session()
session.headers = {"Authorization": f"token {access_token}"}

base_api_endpoint = BASE_API_ENDPOINT

response = session.get(base_api_endpoint)
print(response)

46 changes: 46 additions & 0 deletions segment/analytics/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
from requests.auth import HTTPBasicAuth
from requests import sessions

import requests
from urllib.parse import urlencode

CLIENT_ID = "2TlKP068Khdw4jZaCHuWjXmvui2"
CLIENT_SECRET = "2TlKP068Khdw4jZaCHuWjXmvui2"
REDIRECT_URI = "http://api.segment.build"
BASE_API_ENDPOINT = "http://api.segment.build"

from segment.analytics.version import VERSION
from segment.analytics.utils import remove_trailing_slash

Expand Down Expand Up @@ -59,6 +67,44 @@ def post(write_key, host=None, gzip=False, timeout=15, proxies=None, **kwargs):
except ValueError:
raise APIError(res.status_code, 'unknown', res.text)

class GetOathCode():

def __init__(self, arg):
params = {
"client_id": CLIENT_ID,
"redirect_uri": REDIRECT_URI,
"scope": "scope"
}

endpoint = "http://api.segment.build"
endpoint = endpoint + '?' + urlencode(params)
response = _session.post(endpoint)
self.code = response
return self.code


class GetOathToken():

def __init__(self, arg, code):
params = {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"redirect_uri": REDIRECT_URI,
"code": code,
}
endpoint = "http://api.segment.build/token"
response = requests.post(endpoint, params=params, headers = {"Accept": "application/json"}).json()
access_token = response['access_token']
print("Got Access Token")

session = requests.session()
session.headers = {"Authorization": f"token {access_token}"}

base_api_endpoint = BASE_API_ENDPOINT

response = session.get(base_api_endpoint)
print(response)


class APIError(Exception):

Expand Down

0 comments on commit a411661

Please sign in to comment.