akseljoonas HF Staff commited on
Commit
c4c961e
·
1 Parent(s): de476e8

acess to ml-agent-explorers

Browse files
Files changed (3) hide show
  1. README.md +4 -1
  2. agent/tools/jobs_tool.py +1 -0
  3. backend/routes/auth.py +5 -0
README.md CHANGED
@@ -9,9 +9,10 @@ hf_oauth: true
9
  hf_oauth_scopes:
10
  - read-repos
11
  - write-repos
 
12
  - manage-repos
13
- - inference-api
14
  - jobs
 
15
  ---
16
 
17
  # HF Agent
@@ -50,8 +51,10 @@ ANTHROPIC_API_KEY=<one-key-to-rule-them-all>
50
  HF_TOKEN=<hf-token-to-access-the-hub>
51
  GITHUB_TOKEN=<gh-pat-key-for-not-reinventing-the-wheel>
52
  HF_NAMESPACE=<hf-namespace-to-use>
 
53
  ```
54
 
 
55
  ## Architecture
56
 
57
  ### Component Overview
 
9
  hf_oauth_scopes:
10
  - read-repos
11
  - write-repos
12
+ - contribute-repos
13
  - manage-repos
 
14
  - jobs
15
+ - write-discussions
16
  ---
17
 
18
  # HF Agent
 
51
  HF_TOKEN=<hf-token-to-access-the-hub>
52
  GITHUB_TOKEN=<gh-pat-key-for-not-reinventing-the-wheel>
53
  HF_NAMESPACE=<hf-namespace-to-use>
54
+ HF_OAUTH_ORG_ID=<org-id-for-oauth-org-access>
55
  ```
56
 
57
+
58
  ## Architecture
59
 
60
  ### Component Overview
agent/tools/jobs_tool.py CHANGED
@@ -283,6 +283,7 @@ class HfJobsTool:
283
  namespace: Optional[str] = None,
284
  log_callback: Optional[Callable[[str], Awaitable[None]]] = None,
285
  ):
 
286
  self.api = HfApi(token=hf_token)
287
  self.namespace = namespace
288
  self.log_callback = log_callback
 
283
  namespace: Optional[str] = None,
284
  log_callback: Optional[Callable[[str], Awaitable[None]]] = None,
285
  ):
286
+ self.hf_token = hf_token
287
  self.api = HfApi(token=hf_token)
288
  self.namespace = namespace
289
  self.log_callback = log_callback
backend/routes/auth.py CHANGED
@@ -72,6 +72,11 @@ async def oauth_login(request: Request) -> RedirectResponse:
72
  "response_type": "code",
73
  "state": state,
74
  }
 
 
 
 
 
75
  auth_url = f"{OPENID_PROVIDER_URL}/oauth/authorize?{urlencode(params)}"
76
 
77
  return RedirectResponse(url=auth_url)
 
72
  "response_type": "code",
73
  "state": state,
74
  }
75
+ # Request access to org resources (jobs, repos) so the user's token
76
+ # is scoped to the org.
77
+ org_id = os.environ.get("HF_OAUTH_ORG_ID", "698dbf55845d85df163175f1") # ml-agent-explorers
78
+ if org_id:
79
+ params["orgIds"] = org_id
80
  auth_url = f"{OPENID_PROVIDER_URL}/oauth/authorize?{urlencode(params)}"
81
 
82
  return RedirectResponse(url=auth_url)