@idealyst/oauth-client 1.0.74 → 1.0.75

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/oauth-client",
3
- "version": "1.0.74",
3
+ "version": "1.0.75",
4
4
  "description": "Universal OAuth2 client for web and React Native",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -30,7 +30,8 @@
30
30
  "author": "",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@idealyst/storage": "1.0.74"
33
+ "@idealyst/storage": "1.0.75",
34
+ "crypto": "^1.0.1"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@types/react": "^18.3.18",
@@ -41,7 +42,8 @@
41
42
  "typescript": "^5.7.3"
42
43
  },
43
44
  "peerDependencies": {
44
- "@idealyst/storage": "1.0.74"
45
+ "@idealyst/storage": "1.0.75",
46
+ "react-native": ">=0.60.0"
45
47
  },
46
48
  "files": [
47
49
  "dist",
@@ -35,6 +35,7 @@ export class NativeOAuthClient implements OAuthClient {
35
35
  private async waitForDeepLinkCallback(): Promise<{ code?: string; error?: string; state?: string }> {
36
36
  return new Promise((resolve, reject) => {
37
37
  let subscription: any
38
+ let timeoutId: NodeJS.Timeout | null = null
38
39
 
39
40
  const handleUrl = (event: { url: string }) => {
40
41
  const callbackData = this.parseDeepLink(event.url)
@@ -47,6 +48,12 @@ export class NativeOAuthClient implements OAuthClient {
47
48
  const cleanup = () => {
48
49
  if (subscription?.remove) {
49
50
  subscription.remove()
51
+ } else if (subscription) {
52
+ // For newer React Native versions
53
+ subscription()
54
+ }
55
+ if (timeoutId) {
56
+ clearTimeout(timeoutId)
50
57
  }
51
58
  }
52
59
 
@@ -60,13 +67,15 @@ export class NativeOAuthClient implements OAuthClient {
60
67
  return
61
68
  }
62
69
  }
70
+ }).catch(error => {
71
+ console.warn('Failed to get initial URL:', error)
63
72
  })
64
73
 
65
74
  // Listen for subsequent deep links
66
75
  subscription = Linking.addEventListener('url', handleUrl)
67
76
 
68
77
  // Timeout after 5 minutes
69
- setTimeout(() => {
78
+ timeoutId = setTimeout(() => {
70
79
  cleanup()
71
80
  reject(new Error('OAuth timeout - user did not complete authorization'))
72
81
  }, 5 * 60 * 1000)
@@ -75,6 +84,7 @@ export class NativeOAuthClient implements OAuthClient {
75
84
 
76
85
  private parseDeepLink(url: string): { code?: string; error?: string; state?: string } | null {
77
86
  try {
87
+ // Handle custom scheme URLs (e.g., com.myapp://oauth/callback?code=123)
78
88
  const parsedUrl = new URL(url)
79
89
 
80
90
  // Check if this is our OAuth callback
@@ -83,11 +93,27 @@ export class NativeOAuthClient implements OAuthClient {
83
93
  return null
84
94
  }
85
95
 
86
- // Extract OAuth parameters
96
+ // For custom schemes, parameters are in the query string
87
97
  const code = parsedUrl.searchParams.get('code')
88
98
  const error = parsedUrl.searchParams.get('error')
89
99
  const state = parsedUrl.searchParams.get('state')
90
100
 
101
+ // Also check the hash fragment for parameters (some OAuth providers use this)
102
+ if (!code && !error && parsedUrl.hash) {
103
+ const hashParams = new URLSearchParams(parsedUrl.hash.substring(1))
104
+ const hashCode = hashParams.get('code')
105
+ const hashError = hashParams.get('error')
106
+ const hashState = hashParams.get('state')
107
+
108
+ if (hashCode || hashError) {
109
+ return {
110
+ code: hashCode || undefined,
111
+ error: hashError || undefined,
112
+ state: hashState || undefined
113
+ }
114
+ }
115
+ }
116
+
91
117
  if (!code && !error) {
92
118
  return null
93
119
  }
@@ -98,6 +124,7 @@ export class NativeOAuthClient implements OAuthClient {
98
124
  state: state || undefined
99
125
  }
100
126
  } catch (error) {
127
+ console.warn('Failed to parse deep link URL:', url, error)
101
128
  return null
102
129
  }
103
130
  }
@@ -1,5 +1,5 @@
1
1
  import type { OAuthClient, OAuthConfig, OAuthResult } from './types'
2
-
2
+ import crypto from 'crypto'
3
3
  export class WebOAuthClient implements OAuthClient {
4
4
  private config: OAuthConfig
5
5
 
@@ -8,6 +8,7 @@ export class WebOAuthClient implements OAuthClient {
8
8
  }
9
9
 
10
10
  async authorize(): Promise<OAuthResult> {
11
+ console.log("AAAAAA")
11
12
  const state = this.generateState()
12
13
 
13
14
  // Check if we're already in a callback