@tedbrain/vlink 0.0.0-dpv2.pdkadapt.plugin.0.1.3.r2 → 0.0.0-dpv2.pdkadapt.plugin.0.1.4.r2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.3.r2"}
1
+ {"name": "@tedbrain/vlink", "private": false, "version": "0.0.0-dpv2.pdkadapt.plugin.0.1.4.r2"}
@@ -62,14 +62,16 @@ def save_session(root,envelope,origin):
62
62
  return metadata
63
63
 
64
64
 
65
- def ensure_session(root,origin,exchange,force=False):
65
+ def ensure_session(root,origin,exchange,force=False,allow_account_change=False):
66
66
  token=root/'credentials/token';metadata=root/'credentials/session.json'
67
- if token.is_file() and not force:
68
- if not metadata.is_file():return None # Existing releases renew on a real 401.
67
+ previous=None
68
+ if token.is_file() and metadata.is_file():
69
69
  try:session=loads(metadata.read_bytes())
70
70
  except (OSError,ContractError):raise ContractError('DPV2 session metadata unreadable; use cli.sh login --stdin') from None
71
- if session.get('origin')!=origin:raise ContractError('DPV2 session origin differs; login explicitly for the selected origin')
72
- if session.get('expires_at',0)>time.time()+30:return session
71
+ previous=session.get('subject')
72
+ if session.get('origin')!=origin and not allow_account_change:raise ContractError('DPV2 session origin differs; login explicitly for the selected origin')
73
+ if not force and session.get('expires_at',0)>time.time()+30:return session
74
+ elif token.is_file() and not force:return None # Existing releases renew on a real 401.
73
75
  parsed=urlsplit(origin)
74
76
  official=origin in ('https://tedbrain.com','https://www.tedbrain.com')
75
77
  loopback=(os.environ.get('DPV2_TEST_LOOPBACK')=='1' and parsed.scheme=='http' and
@@ -85,4 +87,6 @@ def ensure_session(root,origin,exchange,force=False):
85
87
  if envelope.get('outcome')=='response' and status in (401,403):
86
88
  raise ContractError('Saved V1 vlink credential rejected; use cli.sh login --stdin')
87
89
  raise ContractError('DPV2 login service unavailable; retry authentication later; business request was not replayed')
90
+ if previous and not allow_account_change and envelope.get('body',{}).get('subject')!=previous:
91
+ raise ContractError('Saved V1 account differs from the DPV2 session; run cli.sh login explicitly to switch accounts; original request was not retried')
88
92
  return save_session(root,envelope,origin)
@@ -169,7 +169,7 @@ def main(argv=None):
169
169
  if not a.stdin:
170
170
  from .auth import saved_credential
171
171
  if saved_credential() is not None:
172
- session=ensure_session(root,origin,lambda credential:exchange_session(root,credential),force=True)
172
+ session=ensure_session(root,origin,lambda credential:exchange_session(root,credential),force=True,allow_account_change=True)
173
173
  print(json.dumps(dict(session,ok=True,reused_v1=True)));return 0
174
174
  if not sys.stdin.isatty():raise ContractError('login required: no saved V1 vlink credential; use login --stdin')
175
175
  credential=sys.stdin.readline().strip() if a.stdin else getpass.getpass('TedBrain invitation code: ')