Skip to content

Commit

Permalink
wiki config updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BrapiCoordinatorSelby committed Sep 11, 2024
1 parent e837d82 commit 0c30597
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ sphinx:
# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
python:
install:
- requirements: docs/requirements.txt
126 changes: 126 additions & 0 deletions Scripts/oauth_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

import requests
import webbrowser
from threading import Lock
from fastapi import FastAPI
import uvicorn
from pyoauth2.client import OAuth2AuthorizationFlow, FileStorage, OAuth2APIRequest
import contextlib
import time
import threading
import uvicorn

class Server(uvicorn.Server):
def install_signal_handlers(self):
pass

@contextlib.contextmanager
def run_in_thread(self):
thread = threading.Thread(target=self.run)
thread.start()
try:
while not self.started:
time.sleep(1e-3)
yield
finally:
self.should_exit = True
thread.join()

class BrAPIRequest(OAuth2APIRequest):
def __init__(self, access_token):
OAuth2APIRequest.__init__(self, access_token)
self.authorization_header = {"Authorization": "Bearer %s" % self.access_token}

code_lock = Lock()
code_val = {"code": ""}

async def root(code: str):
code_val["code"] = code
code_lock.release()

async def lifespan_func(app: FastAPI):
code_lock.acquire()
print("temp server start")
yield
print("temp server shutdown")

def redirect_function(url):
print("hello?")
app = FastAPI(lifespan=lifespan_func)
app.add_api_route("/login/redirect", root)

config = uvicorn.Config(app=app, host="127.0.0.1", port=8000, log_level="info")
server = Server(config=config)
with server.run_in_thread():
webbrowser.open_new_tab(url)
with code_lock:
print(code_val["code"] )

return code_val["code"]


def retrieve_authorization_code(required_params,
extra_auth_params,
extra_token_params, redirect_func=None):
""" retrieve authorization code to get access token
"""

request_param = {
"client_id": required_params['client_id'],
"redirect_uri": required_params['redirect_uri'],
'scope' : required_params['scope']
}

if extra_auth_params:
request_param.update(extra_auth_params)

r = requests.get(required_params['auth_uri'], params=request_param,
allow_redirects=False)
url = r.url
return url

if __name__ == '__main__':

yt_feed_uri = r"https://test-server.brapi.org/brapi/v2/studies"

required_params = {
'client_id': "exampleClient",
'client_secret': "pnosdgBScMmNVc2vpY1cEwBYjsImpAZn",
'auth_uri': "https://auth.brapi.org/realms/brapi/protocol/openid-connect/auth",
'token_uri': "https://test-server.brapi.org/realms/brapi/protocol/openid-connect/token",
'scope': [r'openid profile'],
'redirect_uri': "http://localhost:8000/login/redirect"
}

extra_auth_params = {
'response_type': "code",
'access_type': "offline"
}

extra_token_params = {
'grant_type': "authorization_code",
}

# storage = FileStorage('/example_client.dat')
# credentials = storage.get()
credentials = None
input("proceed?")
if credentials is None:
flow = OAuth2AuthorizationFlow(required_params,
extra_auth_params,
extra_token_params,
False)


code = flow.retrieve_authorization_code(redirect_func=redirect_function)
flow.set_authorization_code(code)
credentials = flow.retrieve_token()
# storage.save(credentials)

access_token = credentials['access_token']

req = BrAPIRequest(access_token)
data = req.request(yt_feed_uri)
print(data)


2 changes: 1 addition & 1 deletion Wiki/Weekly Meeting Notes.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,4 @@ For next week,
http://docs.breeding.apiary.io/, disregarding analysisMethod. Return two
keys: total_markers, missing_values, in JSON
* Lukas will get Rebecca to add us as editors.
* Meet Thursdays at 4pm EDT.
* Meet Thursdays at 4pm EDT.
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
# import sphinx_rtd_theme
# extensions = [
# 'sphinx_rtd_theme'
#]
extensions = [
'sphinx_rtd_theme'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -46,7 +46,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'sphinx_rtd_theme'
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/community/Hackathons_History.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Oct 2021 Virtual Hackathon
October 4, 2021 - October 8, 2021

:Agenda:
`Hackathon Agenda Webpage <https://brapi.org/events/hackathon-oct-2021#agenda-section>`__
`Hackathon Agenda Webpage <https://brapi.org/events/hackathon?id=hackathon-oct-2021#agenda-section>`__
:Topics:
| `Project List <https://brapi.org/events/hackathon-oct-2021#projects-section>`__
| `Notes and Recordings <https://brapi.org/events/hackathon-mar-2021>`__
| `Project List <https://brapi.org/events/hackathon?id=hackathon-oct-2021#projects-section>`__
| `Notes and Recordings <https://brapi.org/events/hackathon?id=hackathon-mar-2021>`__
:Wrap-up:
`Hackathon Debrief News Post (Nov 11, 2021) <https://brapi.org/news/nov-11-2021>`__

Expand All @@ -22,7 +22,7 @@ March 8, 2021 - March 19, 2021
`Hackathon Agenda (Google Doc) <https://docs.google.com/spreadsheets/d/1z9whaJlzTMNuNpq5vVgSxwsmbJfCedPGj3jRfcIX0oE>`__
:Topics:
| `Project List (Google Doc) <https://docs.google.com/document/d/1z4EtlSPTkA8FsopVhHrXSIjTOiEkZDqLW_-RiYFCqVY>`__
| `Notes and Recordings <https://brapi.org/events/hackathon-mar-2021>`__
| `Notes and Recordings <https://brapi.org/events/hackathon?id=hackathon-mar-2021>`__
:Wrap-up:
`Hackathon Debrief News Post (Apr 8, 2021) <https://brapi.org/news/apr-08-2021>`__

Expand Down Expand Up @@ -58,7 +58,7 @@ Sept 10, 2018 - Sept 14, 2018
:Topics:
`Project List (Google Doc) <https://docs.google.com/document/d/1TmqhC5xFHxYpEQXflXwX_y7H7kRLJaYMEaSPKjNf2G4/edit>`__
:Wrap-up:
`Texcoco Hackathon News Post <https://brapi.org/news/sept-27-2018>`__
`Texcoco Hackathon News Post <https://brapi.org/news/sep-27-2018>`__


Feb 2018 Versailles
Expand All @@ -70,7 +70,7 @@ Feb 5, 2018 - Feb 9, 2018
:Topics:
`Topics Google Doc <https://docs.google.com/document/d/11u0qMTgCBjlYfqed5w_CKZULiJAhC4xscIph1Qc3sEY/edit>`__
:Wrap-up:
`Versailles Debrief News Post <https://brapi.org/news.php?id=feb-14-2018>`__
`Versailles Debrief News Post <https://brapi.org/news/feb-14-2018>`__

Jun 2017 Seattle
----------------
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/get_started/Get_Started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Get Started
Here are some notes, tips, and tricks for getting started with the BrAPI specification. For more details, please check the
:doc:`Best Practices </docs/best_practices/best_practices_index>` and the
`BrAPI technical specification <https://brapi.org/specification>`__. If you have any questions, please feel free to
`contact us <https://brapi.org/contacts>`__.
`contact us <https://brapi.org/contact>`__.

- :doc:`Reading the Specification <Get_Started_Reading_The_Spec>` - Tips on how to read the BrAPI Specification effectively
- :doc:`Planning a Use Case <Get_Started_Use_Case>` - Tips for planning an API use case, sending data between two applications
Expand Down

0 comments on commit 0c30597

Please sign in to comment.