You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package is used to get authorization code for Linked In Log in feature using OAuth2 in a easy way. After have the authorization code, you can send it to server to continue to get information needed. For more, please see at [Authenticating with OAuth 2.0 - Linked In](https://developer.linkedin.com/docs/oauth2)
16
+
This package is used to get authorization code for Linked In Log in feature using OAuth2 in a easy way. After have the authorization code, you can exchange to an access token by sending it to the server to continue to get information needed. For more details, please see at [Authorization Code Flow (3-legged OAuth)](https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow)
17
17
See [Usage](#usage) and [Demo](#demo) for instruction.
18
18
19
19
## Table of contents
@@ -34,153 +34,138 @@ See [CHANGELOG.md](https://github.com/nvh95/react-linkedin-login-oauth2/blob/mas
We will create a Linked In button (using `LinkedIn`component), after clicking on this button, a popup window will show up and ask for the permission. After we accepted, the pop up window will redirect to a specified URI which should be routed to `LinkedInCallback` component. It has responsible to notice our openning app the authorization code Linked In provides us. You can consider using `react-router-dom` as a possible solution.
42
+
We will trigger `linkedInLogin` by using `useLinkedIn` (recommended) or `LinkedIn`(using render props technique) after click on Sign in with LinkedIn button, a popup window will show up and ask for the permission. After we accepted, the pop up window will redirect to `redirectUri` (should be `LinkedInCallback` component) then notice its opener about the authorization code Linked In provides us. You can use [react-router-dom](https://reactrouter.com/web) or [Next.js's file system routing](https://nextjs.org/docs/routing/introduction)
43
43
44
44
## Usage
45
45
46
-
First, we create a button and provide required props
47
-
48
-
```
49
-
import React, { Component } from 'react';
50
-
51
-
import { LinkedIn } from 'react-linkedin-login-oauth2';
52
-
import linkedin from 'react-linkedin-login-oauth2/assets/linkedin.png'
53
-
54
-
class LinkedInPage extends Component {
55
-
state = {
56
-
code: '',
57
-
errorMessage: '',
58
-
};
59
-
60
-
61
-
handleSuccess = (data) => {
62
-
this.setState({
63
-
code: data.code,
64
-
errorMessage: '',
65
-
});
66
-
}
67
-
68
-
handleFailure = (error) => {
69
-
this.setState({
70
-
code: '',
71
-
errorMessage: error.errorMessage,
72
-
});
73
-
}
74
-
75
-
render() {
76
-
const { code, errorMessage } = this.state;
77
-
return (
78
-
<div>
79
-
<LinkedIn
80
-
clientId="81lx5we2omq9xh"
81
-
onFailure={this.handleFailure}
82
-
onSuccess={this.handleSuccess}
83
-
redirectUri="http://localhost:3000/linkedin"
84
-
>
85
-
<img src={linkedin} alt="Log in with Linked In" style={{ maxWidth: '180px' }} />
86
-
</LinkedIn>
87
-
{!code && <div>No code</div>}
88
-
{code && <div>Code: {code}</div>}
89
-
{errorMessage && <div>{errorMessage}</div>}
90
-
</div>
91
-
);
92
-
}
46
+
First, we create a button and provide required props:
Then we define a route to `redirect_url`and pass `LinkedInCallback` to it as follow:
112
+
Then we point `redirect_url`to `LinkedInCallback`. You can use [react-router-dom](https://reactrouter.com/web) or [Next.js's file system routing](https://nextjs.org/docs/routing/introduction)
Earlier, this package might not work in IE11. The reason is that if popup and opener do not have same domain, popup cannot send message to opener. For more information about this, please visit [here](https://stackoverflow.com/questions/21070553/postmessage-still-broken-on-ie11). From `1.0.7`, we can bypass this by open a popup to our page, then redirect to Linked In authorization page, it should work fine. IE11 is supported in `1.0.7`. Following is step to support it. (If you don't have need to support IE, please ignore this part)
141
-
142
-
1. Pass prop `supportIE`
143
-
2. Pass `redirectPath` which has path route to `LinkedInCallback` component, default value is `/linkedin` (for above example, `<Route exact path="/linkedin" component={LinkedInCallback} />` => `redirectPath="/linkedin"`)
|||| See your app scope in `https://www.linkedin.com/developers/apps/${yourAppId}/auth`|
169
-
| onSuccess | function | yes ||
170
-
| onFailure | function | yes ||
171
-
| className | string | no | 'btn-linkedin' |
172
-
| style | object | no ||
173
-
| disabled | boolean | no | false |
174
-
| onClick | function | no ||
175
-
| children | function | no | Linked in Signin button |
176
-
| renderElement | function | no | Render prop to use a custom element, use props.onClick |
177
-
| supportIE | boolean | no | false |
178
-
| redirectPath | function | no | /linkedin |
179
-
180
-
Read more about props here [https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context#step-2-request-an-authorization-code](https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context#step-2-request-an-authorization-code)
| state | string | no | randomly generated string (recommend to keep default value) |
161
+
| scope | string | no | 'r_emailaddress' |
162
+
|||| See your app scope [here](https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication?context=linkedin/context#permission-types). If there are more than one, delimited by a space |
163
+
| children | function | no | Require if using `LinkedIn` component (render props) |
0 commit comments