react-native-linkedin-oauth2 1.0.1 → 1.1.1
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 +709 -2
- package/dist/index.d.ts +199 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +646 -2
- package/dist/index.js.map +1 -1
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.d.ts.map +1 -0
- package/dist/setupTests.js +40 -0
- package/dist/setupTests.js.map +1 -0
- package/package.json +37 -6
- package/dist/__tests__/index.test.d.ts +0 -2
- package/dist/__tests__/index.test.d.ts.map +0 -1
- package/dist/__tests__/index.test.js +0 -10
- package/dist/__tests__/index.test.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,200 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file index.tsx
|
|
3
|
+
* @author NikhilRW
|
|
4
|
+
* @description A React Native component that implements LinkedIn OAuth2 authentication
|
|
5
|
+
* using a WebView. It handles the authorization code flow, token exchange, and user profile retrieval.
|
|
6
|
+
*
|
|
7
|
+
* @requires react-native-webview
|
|
8
|
+
* @requires react-native
|
|
9
|
+
* @requires react
|
|
10
|
+
*/
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { type ModalProps, type ViewStyle, type StyleProp } from 'react-native';
|
|
13
|
+
/**
|
|
14
|
+
* Represents the user profile data returned from LinkedIn's /userinfo endpoint.
|
|
15
|
+
* This follows the OpenID Connect standard claims.
|
|
16
|
+
*
|
|
17
|
+
* @interface LinkedInProfile
|
|
18
|
+
*/
|
|
19
|
+
export interface LinkedInProfile {
|
|
20
|
+
/**
|
|
21
|
+
* The unique identifier for the user (Subject).
|
|
22
|
+
* This is a stable identifier for the user.
|
|
23
|
+
*/
|
|
24
|
+
sub: string;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the user's email address has been verified by LinkedIn.
|
|
27
|
+
*/
|
|
28
|
+
email_verified?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The full name of the user.
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* The user's locale information.
|
|
35
|
+
*/
|
|
36
|
+
locale: {
|
|
37
|
+
/** The country code (e.g., US). */
|
|
38
|
+
country: string;
|
|
39
|
+
/** The language code (e.g., en). */
|
|
40
|
+
language: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The user's given name (first name).
|
|
44
|
+
*/
|
|
45
|
+
given_name: string;
|
|
46
|
+
/**
|
|
47
|
+
* The user's family name (last name).
|
|
48
|
+
*/
|
|
49
|
+
family_name: string;
|
|
50
|
+
/**
|
|
51
|
+
* The user's email address.
|
|
52
|
+
* Only present if the 'email' scope was requested and granted.
|
|
53
|
+
*/
|
|
54
|
+
email?: string;
|
|
55
|
+
/**
|
|
56
|
+
* URL to the user's profile picture.
|
|
57
|
+
*/
|
|
58
|
+
picture: string;
|
|
59
|
+
/**
|
|
60
|
+
* Allow for additional properties that might be returned by the API.
|
|
61
|
+
*/
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Represents the response from the LinkedIn Access Token endpoint.
|
|
66
|
+
*
|
|
67
|
+
* @interface LinkedInTokenResponse
|
|
68
|
+
*/
|
|
69
|
+
export interface LinkedInTokenResponse {
|
|
70
|
+
/**
|
|
71
|
+
* The access token used to authorize API requests.
|
|
72
|
+
*/
|
|
73
|
+
access_token: string;
|
|
74
|
+
/**
|
|
75
|
+
* The duration in seconds until the access token expires.
|
|
76
|
+
*/
|
|
77
|
+
expires_in: number;
|
|
78
|
+
/**
|
|
79
|
+
* The scope of access granted by the token.
|
|
80
|
+
*/
|
|
81
|
+
scope: string;
|
|
82
|
+
/**
|
|
83
|
+
* The type of token (usually "Bearer").
|
|
84
|
+
*/
|
|
85
|
+
token_type: string;
|
|
86
|
+
/**
|
|
87
|
+
* The ID token (if OpenID Connect scopes were requested).
|
|
88
|
+
*/
|
|
89
|
+
id_token?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Props for the LinkedInModal component.
|
|
93
|
+
*
|
|
94
|
+
* @interface LinkedInModalProps
|
|
95
|
+
*/
|
|
96
|
+
export interface LinkedInModalProps {
|
|
97
|
+
/**
|
|
98
|
+
* Controls the visibility of the modal.
|
|
99
|
+
*/
|
|
100
|
+
isVisible: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* The Client ID obtained from the LinkedIn Developer Portal.
|
|
103
|
+
* Required for authentication.
|
|
104
|
+
*/
|
|
105
|
+
clientId?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The Client Secret obtained from the LinkedIn Developer Portal.
|
|
108
|
+
* Required for exchanging the authorization code for an access token.
|
|
109
|
+
* @warning Do not expose this in client-side code if possible; consider using a backend proxy for high security.
|
|
110
|
+
*/
|
|
111
|
+
clientSecret?: string;
|
|
112
|
+
/**
|
|
113
|
+
* A space-separated list of permissions to request.
|
|
114
|
+
* Common scopes: 'openid', 'email', 'profile', 'w_member_social'.
|
|
115
|
+
* @default 'openid email profile'
|
|
116
|
+
*/
|
|
117
|
+
scope?: string;
|
|
118
|
+
/**
|
|
119
|
+
* The Redirect URI registered in the LinkedIn Developer Portal.
|
|
120
|
+
* This must match exactly what is configured in the portal.
|
|
121
|
+
*/
|
|
122
|
+
redirectUri?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Callback function triggered when login is successful.
|
|
125
|
+
* @param {LinkedInProfile} user - The profile data of the authenticated user.
|
|
126
|
+
*/
|
|
127
|
+
onSuccess?: (user: LinkedInProfile) => void;
|
|
128
|
+
/**
|
|
129
|
+
* Callback function triggered when an error occurs during authentication.
|
|
130
|
+
* @param {Error} error - The error object containing details about the failure.
|
|
131
|
+
*/
|
|
132
|
+
onError?: (error: Error) => void;
|
|
133
|
+
/**
|
|
134
|
+
* Callback function triggered when the modal is closed (e.g., by the user or after success).
|
|
135
|
+
*/
|
|
136
|
+
onClose?: () => void;
|
|
137
|
+
/**
|
|
138
|
+
* If true, the component will attempt to log the user out of LinkedIn.
|
|
139
|
+
* @default false
|
|
140
|
+
*/
|
|
141
|
+
logout?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Callback function triggered when the logout process is complete.
|
|
144
|
+
*/
|
|
145
|
+
onLogout?: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Custom function to render the header of the modal.
|
|
148
|
+
* @param {Object} props - Props passed to the header renderer.
|
|
149
|
+
* @param {function} props.onClose - Function to close the modal.
|
|
150
|
+
* @returns {React.ReactNode} The custom header component.
|
|
151
|
+
*/
|
|
152
|
+
renderHeader?: (props: {
|
|
153
|
+
onClose: () => void;
|
|
154
|
+
}) => React.ReactNode;
|
|
155
|
+
/**
|
|
156
|
+
* Custom function to render the loading indicator.
|
|
157
|
+
* @returns {React.ReactNode} The custom loading component.
|
|
158
|
+
*/
|
|
159
|
+
renderLoading?: () => React.ReactNode;
|
|
160
|
+
/**
|
|
161
|
+
* Style object for the SafeAreaView container.
|
|
162
|
+
*/
|
|
163
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
164
|
+
/**
|
|
165
|
+
* Style object for the inner wrapper View.
|
|
166
|
+
*/
|
|
167
|
+
wrapperStyle?: StyleProp<ViewStyle>;
|
|
168
|
+
/**
|
|
169
|
+
* Whether to automatically close the modal after a successful login.
|
|
170
|
+
* @default true
|
|
171
|
+
*/
|
|
172
|
+
closeOnSuccess?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Additional props to pass to the underlying React Native Modal component.
|
|
175
|
+
* @see https://reactnative.dev/docs/modal
|
|
176
|
+
*/
|
|
177
|
+
modalProps?: Partial<Omit<ModalProps, 'visible'>>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* LinkedInModal Component.
|
|
181
|
+
*
|
|
182
|
+
* A modal component that loads a WebView to handle LinkedIn OAuth2 authentication.
|
|
183
|
+
*
|
|
184
|
+
* @component
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* <LinkedInModal
|
|
188
|
+
* isVisible={showLinkedInModal}
|
|
189
|
+
* clientId="YOUR_CLIENT_ID"
|
|
190
|
+
* clientSecret="YOUR_CLIENT_SECRET"
|
|
191
|
+
* redirectUri="YOUR_REDIRECT_URI"
|
|
192
|
+
* onSuccess={(user) => console.log(user)}
|
|
193
|
+
* onError={(error) => console.error(error)}
|
|
194
|
+
* onClose={() => setShowLinkedInModal(false)}
|
|
195
|
+
* />
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare const LinkedInModal: React.FC<LinkedInModalProps>;
|
|
199
|
+
export default LinkedInModal;
|
|
2
200
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,EAOL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,SAAS,EAEf,MAAM,cAAc,CAAC;AAOtB;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE;QACN,mCAAmC;QACnC,OAAO,EAAE,MAAM,CAAC;QAChB,oCAAoC;QACpC,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IAEF;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,MA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