Skip to content

Commit 1ba0c2f

Browse files
authored
Authorization fixes (#162)
* Only use scope offline_access for device code and interactive LOGIN. * Protect token cache, also for interactive login. --------- Co-authored-by: Raymond Wiker <rayw@equinor.com>
1 parent 04b194f commit 1ba0c2f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/sumo/wrapper/_auth_provider.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
def scope_for_resource(resource_id):
18-
return f"{resource_id}/.default offline_access"
18+
return f"{resource_id}/.default"
1919

2020

2121
class AuthProvider:
@@ -138,14 +138,17 @@ def __init__(self, client_id, authority, resource_id):
138138
return
139139

140140
def login(self):
141-
result = self._app.acquire_token_interactive([self._scope])
141+
scopes = [self.scope + " offline_access"]
142+
result = self._app.acquire_token_interactive(scopes)
142143

143144
if "error" in result:
144145
raise ValueError(
145146
"Failed to acquire token interactively. Err: %s"
146147
% json.dumps(result, indent=4)
147148
)
148149

150+
protect_token_cache(self._resource_id)
151+
149152
return
150153

151154
pass
@@ -166,7 +169,8 @@ def __init__(self, client_id, authority, resource_id):
166169
return
167170

168171
def login(self):
169-
flow = self._app.initiate_device_flow([self._scope])
172+
scopes = [self.scope + " offline_access"]
173+
flow = self._app.initiate_device_flow(scopes)
170174

171175
if "error" in flow:
172176
raise ValueError(

0 commit comments

Comments
 (0)