@authara/react-native 0.1.1 → 0.2.0

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/README.md CHANGED
@@ -50,6 +50,26 @@ then each request retries once with `Authorization: Bearer …`.
50
50
  `baseUrl` must use HTTPS. Local development can explicitly opt in to HTTP with
51
51
  `allowInsecureHttp: true`; never enable it in production.
52
52
 
53
+ ### Application API clients
54
+
55
+ An application with its own authenticated API can read the current in-memory
56
+ access token without taking ownership of Authara's token lifecycle. Subscribe
57
+ to session changes to synchronize the application's transport, and ask Authara
58
+ to rotate the token after that API returns 401:
59
+
60
+ ```ts
61
+ const unsubscribe = authara.subscribe(() => {
62
+ appApi.setAccessToken(authara.getAccessToken());
63
+ });
64
+
65
+ appApi.setRefreshHandler(() => authara.refreshAccessToken());
66
+ ```
67
+
68
+ `refreshAccessToken()` shares concurrent rotation work and returns the current
69
+ access token or `null`. Refresh tokens remain private and persisted only through
70
+ the configured `AutharaTokenStorage`. Unsubscribe when the application bridge
71
+ is disposed.
72
+
53
73
  ## Native provider adapters
54
74
 
55
75
  Authara accepts small adapters so applications can control their native setup,
package/dist/client.d.ts CHANGED
@@ -46,10 +46,12 @@ export declare class AutharaClient {
46
46
  private readonly listeners;
47
47
  constructor(options: AutharaClientOptions);
48
48
  getSessionSnapshot: () => AutharaSessionSnapshot;
49
+ getAccessToken: () => string | null;
49
50
  subscribe: (listener: () => void) => (() => void);
50
51
  protected setCurrentUser(user: AuthUser | null): void;
51
52
  protected restoreTokens(): Promise<boolean>;
52
53
  signOut(): Promise<void>;
54
+ refreshAccessToken(): Promise<string | null>;
53
55
  protected request<T>(method: string, path: string, options?: {
54
56
  query?: Record<string, QueryValue | undefined>;
55
57
  body?: unknown;
package/dist/client.js CHANGED
@@ -37,6 +37,7 @@ export class AutharaClient {
37
37
  this.fetchImpl = fetchImpl;
38
38
  }
39
39
  getSessionSnapshot = () => this.snapshot;
40
+ getAccessToken = () => this.accessToken;
40
41
  subscribe = (listener) => {
41
42
  this.listeners.add(listener);
42
43
  return () => this.listeners.delete(listener);
@@ -94,6 +95,9 @@ export class AutharaClient {
94
95
  await this.removeStoredRefreshToken(generation);
95
96
  }
96
97
  }
98
+ async refreshAccessToken() {
99
+ return (await this.refresh()) ? this.accessToken : null;
100
+ }
97
101
  async request(method, path, options = {}) {
98
102
  let generation = this.sessionGeneration;
99
103
  const query = { ...options.query };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authara/react-native",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Official React Native client, hooks, and native-provider buttons for Authara",
5
5
  "keywords": [
6
6
  "authentication",