Exemplo n.º 1
0
    def createSession(self):
        session = OAuth2Session(self.client_id,
                                scope=self.scope,
                                redirect_uri=self.redirect_uri)

        if (self.authorization_base_url ==
                'https://www.linkedin.com/uas/oauth2/authorization'):
            session = linkedin_compliance_fix(session)

        authorization_url, state = session.authorization_url(
            self.authorization_base_url,
            access_type="offline",
            approval_prompt="force")

        print('Please go here and authorize,', authorization_url)

        redirect_response = input('Paste the full authorization token here:')

        session.fetch_token(self.token_url,
                            client_secret=self.client_secret,
                            code=redirect_response)

        self._setTokenInDataStore(session.token)
        self.token = session.token

        return session
Exemplo n.º 2
0
def main():

    #__init__
    client_id = '81jfp87tuel89d'
    client_secret = 'FANBGNhDSJbaMmV1'
    return_url = 'https://localhost:8888'
    authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'

    #
    linkedin_oauth2 = OAuth2Session(client_id, redirect_uri=return_url)
    linkedin_oauth2 = linkedin_compliance_fix(linkedin_oauth2)
    authorization_url, state = linkedin_oauth2.authorization_url(
        authorization_base_url)
    print('Please go here and authorize:\n{}'.format(authorization_url))
    webbrowser.open(authorization_url)
    redirect_response = input('Paste the full redirect URL here:')
    linkedin_oauth2.fetch_token(token_url,
                                client_secret=client_secret,
                                authorization_response=redirect_response)
    r = linkedin_oauth2.get('https://api.linkedin.com/v1/people/~')

    #__API叩いた結果を表示__
    result = xmltodict.parse(r.content.decode('utf-8'))
    result = json.dumps(result, indent=2)
    print(result.encode().decode('unicode-escape'))
Exemplo n.º 3
0
def make_json(redirect_response):
    linkedin = OAuth2Session(CLIENT_ID, redirect_uri=RETURN_URL)
    linkedin = linkedin_compliance_fix(linkedin)
    linkedin.fetch_token(TOKEN_URL, client_secret=CLIENT_SECRET, authorization_response=redirect_response)
    info = linkedin.get("https://api.linkedin.com/v1/people/~:(id,email-address,first-name,last-name,industry,positions,summary,headline,location)/?format=json")
    infoJson = json.loads(info.content)
    file = open('resume.json','w+')
    file.write(info.content)
    file.close()
Exemplo n.º 4
0
def get_access_token(provider, authorization_response, redirect_uri):
    if provider == Provider.GOOGLE:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GOOGLE']['client_id'],
            redirect_uri=redirect_uri
        )
        ret = p.fetch_token(
            GOOGLE_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['GOOGLE']['client_secret'],
            authorization_response=authorization_response
        )

        return ret['access_token']
    elif provider == Provider.FACEBOOK:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['FACEBOOK']['client_id'],
            redirect_uri=redirect_uri
        )

        from requests_oauthlib.compliance_fixes import facebook_compliance_fix

        p = facebook_compliance_fix(p)
        ret = p.fetch_token(
            FACEBOOK_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['FACEBOOK']['client_secret'],
            authorization_response=authorization_response
        )

        return ret['access_token']
    elif provider == Provider.GITHUB or provider.upper() == Provider.GITHUB:
        p = OAuth2Session(client_id=settings.STORMPATH_SOCIAL['GITHUB']['client_id'])
        ret = p.fetch_token(
            GITHUB_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['GITHUB']['client_secret'],
            authorization_response=authorization_response
        )

        return ret['access_token']
    elif provider == Provider.LINKEDIN:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['LINKEDIN']['client_id'],
            redirect_uri=redirect_uri
        )

        from requests_oauthlib.compliance_fixes import linkedin_compliance_fix

        p = linkedin_compliance_fix(p)
        ret = p.fetch_token(
            LINKEDIN_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['LINKEDIN']['client_secret'],
            authorization_response=authorization_response
        )

        return ret['access_token']
    else:
        return None
Exemplo n.º 5
0
 def linkedin_oauth(self, **kw):
     Oauth = request.env['oauth.oauth']
     linkedin = Oauth.sudo().get_provider('Linkedin')
     callback_uri = self.get_callback_url('linkedin')
     oauth_session = OAuth2Session(linkedin.client_id,
                                   redirect_uri=callback_uri)
     oauth_session = linkedin_compliance_fix(oauth_session)
     authorization_url, state = oauth_session.authorization_url(
         linkedin.auth_endpoint)
     return http.redirect_with_hash(authorization_url)
Exemplo n.º 6
0
def auth_linkedin_entry():
    linkedin = config["LINKEDIN"]
    linkedin_session = OAuth2Session(linkedin["client_id"],
                                     redirect_uri=linkedin["redirect_uri"])

    linkedin_session = linkedin_compliance_fix(linkedin_session)
    authorization_url, state = linkedin_session.authorization_url(
                                                        linkedin['auth_url'])
    login_session["state"] = state
    return redirect(authorization_url)
Exemplo n.º 7
0
 def get_auth_link(self, auth_storage, share=False):
     linkedin = OAuth2Session(self._client_id,
                              scope=scope + (["w_share"] if share else []),
                              redirect_uri=web.ctx.home +
                              self._callback_page)
     linkedin = linkedin_compliance_fix(linkedin)
     authorization_url, state = linkedin.authorization_url(
         authorization_base_url)
     auth_storage["oauth_state"] = state
     return authorization_url
Exemplo n.º 8
0
def callback():
    redirect_uri = current_app.config['REDIRECT_URI_BASE'] + 'oauth2/callback'
    oauth = OAuth2Session(client_id,
                          redirect_uri=redirect_uri,
                          state=session['oauth_state'])
    oauth = linkedin_compliance_fix(oauth)
    token = oauth.fetch_token(
        'https://www.linkedin.com/uas/oauth2/accessToken',
        client_secret=client_secret,
        code=request.args.get('code', ''))
    session['oauth_token'] = token
    return redirect(url_for('.share_entry', url=session['url']))
    def test_fetch_access_token(self):
        linkedin = OAuth2Session('foo', redirect_uri='https://i.b')
        linkedin = linkedin_compliance_fix(linkedin)

        linkedin.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response._content = '{"access_token":"linkedin"}'.encode('UTF-8')
        linkedin.post.return_value = response

        token = linkedin.fetch_token('https://mocked.out',
                                     client_secret='bar',
                                     authorization_response='https://i.b/?code=hello')
        self.assertEqual(token, {'access_token': 'linkedin', 'token_type': 'Bearer'})
Exemplo n.º 10
0
def get_access_token(provider, authorization_response, redirect_uri):
    if provider == Provider.GOOGLE:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GOOGLE']['client_id'],
            redirect_uri=redirect_uri)
        ret = p.fetch_token(
            GOOGLE_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['GOOGLE']['client_secret'],
            authorization_response=authorization_response)

        return ret['access_token']
    elif provider == Provider.FACEBOOK:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['FACEBOOK']['client_id'],
            redirect_uri=redirect_uri)

        from requests_oauthlib.compliance_fixes import facebook_compliance_fix

        p = facebook_compliance_fix(p)
        ret = p.fetch_token(FACEBOOK_TOKEN_URL,
                            client_secret=settings.STORMPATH_SOCIAL['FACEBOOK']
                            ['client_secret'],
                            authorization_response=authorization_response)

        return ret['access_token']
    elif provider == Provider.GITHUB or provider.upper() == Provider.GITHUB:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GITHUB']['client_id'])
        ret = p.fetch_token(
            GITHUB_TOKEN_URL,
            client_secret=settings.STORMPATH_SOCIAL['GITHUB']['client_secret'],
            authorization_response=authorization_response)

        return ret['access_token']
    elif provider == Provider.LINKEDIN:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['LINKEDIN']['client_id'],
            redirect_uri=redirect_uri)

        from requests_oauthlib.compliance_fixes import linkedin_compliance_fix

        p = linkedin_compliance_fix(p)
        ret = p.fetch_token(LINKEDIN_TOKEN_URL,
                            client_secret=settings.STORMPATH_SOCIAL['LINKEDIN']
                            ['client_secret'],
                            authorization_response=authorization_response)

        return ret['access_token']
    else:
        return None
    def test_fetch_access_token(self):
        linkedin = OAuth2Session("foo", redirect_uri="https://i.b")
        linkedin = linkedin_compliance_fix(linkedin)

        linkedin.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response.request = mock.MagicMock()
        response._content = '{"access_token":"linkedin"}'.encode("UTF-8")
        linkedin.post.return_value = response

        token = linkedin.fetch_token(
            "https://mocked.out", client_secret="bar", authorization_response="https://i.b/?code=hello"
        )
        self.assertEqual(token, {"access_token": "linkedin", "token_type": "Bearer"})
Exemplo n.º 12
0
def get_authorization_url(provider, redirect_uri):
    if provider == Provider.GOOGLE:
        scope = ['email', "profile"]
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GOOGLE']['client_id'],
            scope=scope,
            redirect_uri=redirect_uri)
        authorization_url, state = p.authorization_url(
            GOOGLE_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.FACEBOOK:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['FACEBOOK']['client_id'],
            redirect_uri=redirect_uri)

        from requests_oauthlib.compliance_fixes import facebook_compliance_fix

        p = facebook_compliance_fix(p)
        authorization_url, state = p.authorization_url(
            FACEBOOK_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.GITHUB or provider.upper() == Provider.GITHUB:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GITHUB']['client_id'])
        authorization_url, state = p.authorization_url(
            GITHUB_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.LINKEDIN:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['LINKEDIN']['client_id'],
            redirect_uri=redirect_uri)

        from requests_oauthlib.compliance_fixes import linkedin_compliance_fix

        p = linkedin_compliance_fix(p)
        authorization_url, state = p.authorization_url(
            LINKEDIN_AUTHORIZATION_BASE_URL)

        return authorization_url, state
    else:
        raise RuntimeError('Invalid Provider {}'.format(provider))
Exemplo n.º 13
0
def get_authorization_url(provider, redirect_uri):
    if provider == Provider.GOOGLE:
        scope = ['email', "profile"]
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['GOOGLE']['client_id'],
            scope=scope,
            redirect_uri=redirect_uri
        )
        authorization_url, state = p.authorization_url(GOOGLE_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.FACEBOOK:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['FACEBOOK']['client_id'],
            redirect_uri=redirect_uri
        )

        from requests_oauthlib.compliance_fixes import facebook_compliance_fix

        p = facebook_compliance_fix(p)
        authorization_url, state = p.authorization_url(FACEBOOK_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.GITHUB or provider.upper() == Provider.GITHUB:
        p = OAuth2Session(client_id=settings.STORMPATH_SOCIAL['GITHUB']['client_id'])
        authorization_url, state = p.authorization_url(GITHUB_AUTHORIZATION_BASE_URL)

        return authorization_url, state

    elif provider == Provider.LINKEDIN:
        p = OAuth2Session(
            client_id=settings.STORMPATH_SOCIAL['LINKEDIN']['client_id'],
            redirect_uri=redirect_uri
        )

        from requests_oauthlib.compliance_fixes import linkedin_compliance_fix

        p = linkedin_compliance_fix(p)
        authorization_url, state = p.authorization_url(LINKEDIN_AUTHORIZATION_BASE_URL)

        return authorization_url, state
    else:
        raise RuntimeError('Invalid Provider {}'.format(provider))
Exemplo n.º 14
0
	def createSession(self):
		session = OAuth2Session(self.client_id, scope=self.scope, redirect_uri=self.redirect_uri)
		
		if(self.authorization_base_url == 'https://www.linkedin.com/uas/oauth2/authorization'):
			session = linkedin_compliance_fix(session)
			
		authorization_url, state = session.authorization_url(self.authorization_base_url, access_type="offline", approval_prompt="force")
		
		print('Please go here and authorize,', authorization_url)
		
		redirect_response = input('Paste the full authorization token here:')
		
		session.fetch_token(self.token_url, client_secret=self.client_secret, code=redirect_response)
		
		self._setTokenInDataStore(session.token)
		self.token = session.token
		
		return session
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://www.linkedin.com/uas/oauth2/accessToken",
            json={"access_token": "linkedin"},
        )
        mocker.post(
            "https://api.linkedin.com/v1/people/~/shares",
            status_code=201,
            json={
              "updateKey": "UPDATE-3346389-595113200",
              "updateUrl": "https://www.linkedin.com/updates?discuss=abc&scope=xyz"
            }
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        linkedin = OAuth2Session('someclientid', redirect_uri='https://i.b')
        self.session = linkedin_compliance_fix(linkedin)
Exemplo n.º 16
0
def createApp():
    client_id    = access_token[0].strip()
    client_secret = access_token[1].strip()
    authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'
    RETURN_URL = "https://smop.io"

    linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1')
    linkedin = linkedin_compliance_fix(linkedin)

    authorization_url, state = linkedin.authorization_url(
        authorization_base_url)
    print ('Please go here and authorize,', authorization_url)

    redirect_response = input('Paste the full redirect URL here:')

    linkedin.fetch_token(token_url, client_secret=client_secret,
                         authorization_response=redirect_response)
    return linkedin
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://www.linkedin.com/uas/oauth2/accessToken",
            json={"access_token": "linkedin"},
        )
        mocker.post(
            "https://api.linkedin.com/v1/people/~/shares",
            status_code=201,
            json={
                "updateKey": "UPDATE-3346389-595113200",
                "updateUrl": "https://www.linkedin.com/updates?discuss=abc&scope=xyz",
            },
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        linkedin = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = linkedin_compliance_fix(linkedin)
Exemplo n.º 18
0
    def test_fetch_access_token(self):
        linkedin = OAuth2Session('foo', redirect_uri='https://i.b')
        linkedin = linkedin_compliance_fix(linkedin)

        linkedin.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response.request = mock.MagicMock()
        response._content = '{"access_token":"linkedin"}'.encode('UTF-8')
        linkedin.post.return_value = response

        token = linkedin.fetch_token(
            'https://mocked.out',
            client_secret='bar',
            authorization_response='https://i.b/?code=hello')
        self.assertEqual(token, {
            'access_token': 'linkedin',
            'token_type': 'Bearer'
        })
Exemplo n.º 19
0
def main():

     #__init__
    client_id  = '81jfp87tuel89d'
    client_secret = 'FANBGNhDSJbaMmV1'
    return_url = 'https://localhost:8888'
    authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'


    linkedin_oauth2 = OAuth2Session(client_id, redirect_uri=return_url)
    linkedin_oauth2 = linkedin_compliance_fix(linkedin_oauth2)
    authorization_url, state = linkedin_oauth2.authorization_url(authorization_base_url)
    print('Please go here and authorize:\n{}'.format(authorization_url))
    webbrowser.open(authorization_url)
    redirect_response = input('Paste the full redirect URL here:')
    match_obj = redirect_response.split('code=')[1].split('&state')[0]
    print()
    print(match_obj)
    authentication.authorization_code = match_obj
    authentication.get_access_token()
def get_linkedin_profile():
    client_id = secrets.Client_ID
    client_secret = secrets.Client_Secret
    redirect_uri = 'https://www.google.com/'

    base_url = 'https://www.linkedin.com/jobs/search/'
    authorization_base_url = 'https://www.linkedin.com/oauth/v2/authorization'
    token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'

    linkedin = OAuth2Session(client_id, redirect_uri=redirect_uri)
    linkedin = linkedin_compliance_fix(linkedin)
    authorization_url, state = linkedin.authorization_url(
        authorization_base_url)
    search_term = input('Can I get the permission to access your acount? Y/N')
    if search_term.upper() == 'Y':
        print('Please go here and authorize,', authorization_url)

        # Get the authorization verifier code from the callback url
        redirect_response = input('Paste the full redirect URL here:')

        # Fetch the access token
        linkedin.fetch_token(token_url,
                             client_secret=client_secret,
                             authorization_response=redirect_response)

        # Fetch a protected resource, i.e. user profile
        r = linkedin.get('https://api.linkedin.com/v1/people/~?format=json')
        profile_dict = json.loads(r.content)
        firstName = profile_dict['firstName']
        lastName = profile_dict['lastName']
        url = profile_dict['siteStandardProfileRequest']['url']
        profile = Profile(firstName, lastName, url)
        return profile
    if search_term.upper() == 'N':
        manual_profile = input('Please enter your name or exit:')
        if manual_profile != 'exit':
            return manual_profile
Exemplo n.º 21
0
 def get_auth_link(self, user_manager):
         linkedin = OAuth2Session(self._client_id, redirect_uri=web.ctx.home + self._callback_page)
         linkedin = linkedin_compliance_fix(linkedin)
         authorization_url, state = linkedin.authorization_url(authorization_base_url)
         user_manager.set_session_oauth_state(state)
         return authorization_url
# options.headless = True
# options.add_argument
# Create a Firefox Driver Session
# firefox_profile = webdriver.FirefoxProfile()
# firefox_profile.set_preference("browser.privatebrowsing.autostart", True)

# driver = webdriver.Firefox(firefox_options=options,firefox_profile=firefox_profile)


# driver.delete_all_cookies()
# driver = webdriver.Firefox()

# Read secrets:
# Initialize the Linked In Session to get the Authorization URL
linkedin = OAuth2Session(client_id, redirect_uri='https://www.getpostman.com/oauth2/callback')
linkedin = linkedin_compliance_fix(linkedin)
authorization_url, state = linkedin.authorization_url(authorization_base_url)
start = 0

browser = mechanicalsoup.StatefulBrowser()
browser.open(authorization_url)
browser.select_form("form[action=https://www.linkedin.com/uas/login-submit]")
browser['session_key'] = session_key
browser['session_password'] = session_password
browser.submit_selected()
urlparse(browser.get_url())
# Open the Authorization URL in the Broswer
# driver.get(authorization_url)
# Key in the Username and Password
# id_box = driver.find_element_by_name('session_key')
# id_box.send_keys(session_key)
Exemplo n.º 23
0
CLIENT_ID = secrets.get('client_id')
CLIENT_SECRET = secrets.get('client_secret')
REDIRECT_URI = secrets.get('redirect_uri')
ACCESS_TOKEN_URL = secrets.get('access_token_url')
REDIRECT_RESPONSE = secrets.get('redirect_response')

oauth = OAuth2Session(client_id=CLIENT_ID, redirect_uri=REDIRECT_URI)

# Get the authorization verifier code from the callback url
#redirect_response = input('Paste the full redirect URL here:')

redirect_response = REDIRECT_RESPONSE

# Fetch the access token
linkedin = linkedin_compliance_fix(oauth)
linkedin.fetch_token(ACCESS_TOKEN_URL,
                     client_secret=CLIENT_SECRET,
                     authorization_response=redirect_response)

#print(linkedin.token)
token_value = linkedin.token
ACCESS_TOKEN_VALUE = token_value.get('access_token')

print('Valor do ACCESS TOKEN fornecido:', '\n')
print(ACCESS_TOKEN_VALUE)
print('\n')
print(token_value.items())
print('\n')

# escrevendo o conteúdo do TOKEN no arquivo
Exemplo n.º 24
0
 def get_auth_link(self, auth_storage, share=False):
     linkedin = OAuth2Session(self._client_id, scope=scope + (["w_share"] if share else []), redirect_uri=web.ctx.home + self._callback_page)
     linkedin = linkedin_compliance_fix(linkedin)
     authorization_url, state = linkedin.authorization_url(authorization_base_url)
     auth_storage["oauth_state"] = state
     return authorization_url
Exemplo n.º 25
0
 def get_auth_client(self):
     _auth_client = OAuth2Session(self.client_id, scope=self.scopes, redirect_uri=self.get_redirect_uri())
     _auth_client = linkedin_compliance_fix(_auth_client)
     return _auth_client
Exemplo n.º 26
0
def author():
    linkedin = OAuth2Session(CLIENT_ID, redirect_uri=RETURN_URL)
    linkedin = linkedin_compliance_fix(linkedin)
    authorization_url, state = linkedin.authorization_url(AUTHORIZATION_BASE_URL)
    return authorization_url