@@ -2,6 +2,15 @@ import React, { Component } from 'react';
22import PropTypes from 'prop-types' ;
33import '../assets/index.css' ;
44
5+ const getPopupPositionProperties = ( {
6+ width = 600 ,
7+ height = 600 ,
8+ } ) => {
9+ const left = ( screen . width / 2 ) - ( width / 2 ) ;
10+ const top = ( screen . height / 2 ) - ( height / 2 ) ;
11+ return `left=${ left } ,top=${ top } ,width=${ width } ,height=${ height } ` ;
12+ }
13+
514export class LinkedIn extends Component {
615 static propTypes = {
716 className : PropTypes . string ,
@@ -20,9 +29,8 @@ export class LinkedIn extends Component {
2029 }
2130
2231 getUrl = ( ) => {
23- const { redirectUri, clientId, state, scope, supportIE, redirectPath } = this . props ;
24- // TODO: Support IE 11
25- const scopeParam = ( scope ) ? `&scope=${ supportIE ? scope : encodeURI ( scope ) } ` : '' ;
32+ const { redirectUri, clientId, state, scope, supportIE, redirectPath } = this . props ;
33+ const scopeParam = `&scope=${ supportIE ? scope : encodeURI ( scope ) } ` ;
2634 const linkedInAuthenLink = `https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=${ clientId } &redirect_uri=${ redirectUri } ${ scopeParam } &state=${ state } ` ;
2735 if ( supportIE ) {
2836 const redirectLink = `${ window . location . origin } ${ redirectPath } ?linkedin_redirect_url=${ encodeURIComponent ( linkedInAuthenLink ) } ` ;
@@ -32,19 +40,19 @@ export class LinkedIn extends Component {
3240 }
3341
3442 receiveMessage = ( event ) => {
35- const { state } = this . props ;
43+ const { state } = this . props ;
3644 if ( event . origin === window . location . origin ) {
3745 if ( event . data . errorMessage && event . data . from === 'Linked In' ) {
3846 // Prevent CSRF attack by testing state
39- if ( event . data . state !== state ) {
47+ if ( event . data . state !== state ) {
4048 this . popup && this . popup . close ( ) ;
4149 return ;
4250 }
4351 this . props . onFailure ( event . data ) ;
4452 this . popup && this . popup . close ( ) ;
4553 } else if ( event . data . code && event . data . from === 'Linked In' ) {
4654 // Prevent CSRF attack by testing state
47- if ( event . data . state !== state ) {
55+ if ( event . data . state !== state ) {
4856 this . popup && this . popup . close ( ) ;
4957 return ;
5058 }
@@ -59,7 +67,7 @@ export class LinkedIn extends Component {
5967 e . preventDefault ( ) ;
6068 }
6169 this . props . onClick && this . props . onClick ( ) ;
62- this . popup = window . open ( this . getUrl ( ) , '_blank' , ' width= 600,height= 600' ) ;
70+ this . popup = window . open ( this . getUrl ( ) , '_blank' , getPopupPositionProperties ( { width : 600 , height : 600 } ) ) ;
6371 window . removeEventListener ( 'message' , this . receiveMessage , false ) ;
6472 window . addEventListener ( 'message' , this . receiveMessage , false ) ;
6573 }
@@ -90,6 +98,7 @@ LinkedIn.defaultProps = {
9098 children : ( < img src = { require ( '../assets/linkedin.png' ) } alt = "Log in with Linked In" style = { { maxWidth : '180px' } } /> ) ,
9199 state : 'fdsf78fyds7fm' ,
92100 supportIE : false ,
93- redirectPath : '/linkedin'
101+ redirectPath : '/linkedin' ,
102+ scope : 'r_emailaddress' ,
94103} ;
95104export default LinkedIn ;
0 commit comments