Exemplo n.º 1
0
  def test_json_credentials_storage(self):
    access_token = 'foo'
    client_id = 'some_client_id'
    client_secret = 'cOuDdkfjxxnv+'
    refresh_token = '1/0/a.df219fjls0'
    token_expiry = datetime.datetime.utcnow()
    user_agent = 'refresh_checker/1.0'

    credentials = OAuth2Credentials(
        access_token, client_id, client_secret,
        refresh_token, token_expiry, GOOGLE_TOKEN_URI,
        user_agent)

    m = mox.Mox()
    m.StubOutWithMock(keyring, 'get_password')
    m.StubOutWithMock(keyring, 'set_password')
    keyring.get_password('my_unit_test', 'me').AndReturn(None)
    keyring.set_password('my_unit_test', 'me', credentials.to_json())
    keyring.get_password('my_unit_test', 'me').AndReturn(credentials.to_json())
    m.ReplayAll()

    s = Storage('my_unit_test', 'me')
    self.assertEquals(None, s.get())

    s.put(credentials)

    restored = s.get()
    self.assertEqual('foo', restored.access_token)
    self.assertEqual('some_client_id', restored.client_id)

    m.UnsetStubs()
    m.VerifyAll()
    def test_json_credentials_storage(self):
        access_token = 'foo'
        client_id = 'some_client_id'
        client_secret = 'cOuDdkfjxxnv+'
        refresh_token = '1/0/a.df219fjls0'
        token_expiry = datetime.datetime.utcnow()
        token_uri = 'https://www.google.com/accounts/o8/oauth2/token'
        user_agent = 'refresh_checker/1.0'

        credentials = OAuth2Credentials(access_token, client_id, client_secret,
                                        refresh_token, token_expiry, token_uri,
                                        user_agent)

        m = mox.Mox()
        m.StubOutWithMock(keyring, 'get_password')
        m.StubOutWithMock(keyring, 'set_password')
        keyring.get_password('my_unit_test', 'me').AndReturn(None)
        keyring.set_password('my_unit_test', 'me', credentials.to_json())
        keyring.get_password('my_unit_test',
                             'me').AndReturn(credentials.to_json())
        m.ReplayAll()

        s = Storage('my_unit_test', 'me')
        self.assertEquals(None, s.get())

        s.put(credentials)

        restored = s.get()
        self.assertEqual('foo', restored.access_token)
        self.assertEqual('some_client_id', restored.client_id)

        m.UnsetStubs()
        m.VerifyAll()
def get_credentials(code):
	if code:
		params = get_oauth_keys('gcal')
		params.update({
			"scope": 'https://www.googleapis.com/auth/calendar',
			"redirect_uri": get_redirect_uri('calendar'),
			"params": {
				"approval_prompt":"force",
				'access_type': 'offline',
				"response_type": "code"
			}
		})
		flow = OAuth2WebServerFlow(**params)
		credentials = flow.step2_exchange(code)
		# Store Credentials in Keyring Storage
		store = Storage('Google Account', frappe.session.user)
		store.put(credentials)
		
		frappe.get_doc({
			"doctype": "Google Account",
			"name": frappe.session.user,
			"authenticated": 1
		}).save(ignore_permissions=True)
		
		frappe.local.response["type"] = "redirect"
		frappe.local.response["location"] = "/desk#Form/Google Account/%s", frappe.sesion.user
Exemplo n.º 4
0
def get_credentials(code):
    if code:
        params = get_oauth_keys('gcal')
        params.update({
            "scope": 'https://www.googleapis.com/auth/calendar',
            "redirect_uri": get_redirect_uri('calendar'),
            "params": {
                "approval_prompt": "force",
                'access_type': 'offline',
                "response_type": "code"
            }
        })
        flow = OAuth2WebServerFlow(**params)
        credentials = flow.step2_exchange(code)
        # Store Credentials in Keyring Storage
        store = Storage('Google Account', frappe.session.user)
        store.put(credentials)

        frappe.get_doc({
            "doctype": "Google Account",
            "name": frappe.session.user,
            "authenticated": 1
        }).save(ignore_permissions=True)

        frappe.local.response["type"] = "redirect"
        frappe.local.response[
            "location"] = "/desk#Form/Google Account/%s", frappe.sesion.user
Exemplo n.º 5
0
    def get_credentials(self):

        storage = Storage(self.appname, os.getlogin())

        credentials = storage.get()
        if not credentials or credentials.invalid:
            credentials = self.request_credentials()
            storage.put(credentials)

        return credentials
Exemplo n.º 6
0
    def get_credentials(self):

        storage = Storage(self.appname, os.getlogin())

        credentials = storage.get()
        if not credentials or credentials.invalid:
            credentials = self.request_credentials()
            storage.put(credentials)

        return credentials
Exemplo n.º 7
0
    def test_json_credentials_storage(self):
        access_token = 'foo'
        client_id = 'some_client_id'
        client_secret = 'cOuDdkfjxxnv+'
        refresh_token = '1/0/a.df219fjls0'
        token_expiry = datetime.datetime.utcnow()
        user_agent = 'refresh_checker/1.0'

        credentials = OAuth2Credentials(access_token, client_id, client_secret,
                                        refresh_token, token_expiry,
                                        GOOGLE_TOKEN_URI, user_agent)

        # Setting autospec on a mock with an iterable side_effect is
        # currently broken (http://bugs.python.org/issue17826), so instead
        # we patch twice.
        with mock.patch.object(keyring,
                               'get_password',
                               return_value=None,
                               autospec=True) as get_password:
            with mock.patch.object(keyring,
                                   'set_password',
                                   return_value=None,
                                   autospec=True) as set_password:
                s = Storage('my_unit_test', 'me')
                self.assertEquals(None, s.get())

                s.put(credentials)

                set_password.assert_called_once_with('my_unit_test', 'me',
                                                     credentials.to_json())
                get_password.assert_called_once_with('my_unit_test', 'me')

        with mock.patch.object(keyring,
                               'get_password',
                               return_value=credentials.to_json(),
                               autospec=True) as get_password:
            restored = s.get()
            self.assertEqual('foo', restored.access_token)
            self.assertEqual('some_client_id', restored.client_id)
            get_password.assert_called_once_with('my_unit_test', 'me')
    def test_get_and_set_with_json_credentials_stored(self):
        access_token = 'foo'
        client_id = 'some_client_id'
        client_secret = 'cOuDdkfjxxnv+'
        refresh_token = '1/0/a.df219fjls0'
        token_expiry = datetime.datetime.utcnow()
        user_agent = 'refresh_checker/1.0'

        credentials = OAuth2Credentials(
            access_token, client_id, client_secret,
            refresh_token, token_expiry, GOOGLE_TOKEN_URI,
            user_agent)

        # Setting autospec on a mock with an iterable side_effect is
        # currently broken (http://bugs.python.org/issue17826), so instead
        # we patch twice.
        with mock.patch.object(keyring, 'get_password',
                               return_value=None,
                               autospec=True) as get_password:
            with mock.patch.object(keyring, 'set_password',
                                   return_value=None,
                                   autospec=True) as set_password:
                store = Storage('my_unit_test', 'me')
                self.assertEquals(None, store.get())

                store.put(credentials)

                set_password.assert_called_once_with(
                    'my_unit_test', 'me', credentials.to_json())
                get_password.assert_called_once_with('my_unit_test', 'me')

        with mock.patch.object(keyring, 'get_password',
                               return_value=credentials.to_json(),
                               autospec=True) as get_password:
            restored = store.get()
            self.assertEqual('foo', restored.access_token)
            self.assertEqual('some_client_id', restored.client_id)
            get_password.assert_called_once_with('my_unit_test', 'me')
Exemplo n.º 9
0
def get_credentials(code):
    if code:
        params = get_oauth_keys('gcal')
        params.update({
            "scope": 'https://www.googleapis.com/auth/calendar',
            "redirect_uri": get_redirect_uri('gcal'),
            "params": {
                "approval_prompt": "force",
                'access_type': 'offline',
                "response_type": "code"
            }
        })
        flow = OAuth2WebServerFlow(**params)
        credentials = flow.step2_exchange(code)
        # Store Credentials in Keyring Storage
        store = Storage('GCal', frappe.session.user)
        store.put(credentials)
        # get events and create new doctype
        from gcal.tasks import sync_google_calendar
        sync_google_calendar(credentials)

    frappe.local.response["type"] = "redirect"
    frappe.local.response["location"] = "/desk#Calendar/Event"
Exemplo n.º 10
0
def get_credentials(code):
	if code:
		params = get_oauth_keys('gcal')
		params.update({
			"scope": 'https://www.googleapis.com/auth/calendar',
			"redirect_uri": get_redirect_uri('gcal'),
			"params": {
				"approval_prompt":"force",
				'access_type': 'offline',
				"response_type": "code"
			}
		})
		flow = OAuth2WebServerFlow(**params)
		credentials = flow.step2_exchange(code)
		# Store Credentials in Keyring Storage
		store = Storage('GCal', frappe.session.user)
		store.put(credentials)
		# get events and create new doctype
		from gcal.tasks import sync_google_calendar
		sync_google_calendar(credentials)

	frappe.local.response["type"] = "redirect"
	frappe.local.response["location"] = "/desk#Calendar/Event"
import json
from cmislib.model import CmisClient
import os, pwd

uid = pwd.getpwuid(os.getuid())[0]
storage = Storage("Jeff's Sample Python App", uid)
http = Http(
    disable_ssl_certificate_validation=True)  # Should not have to do this!
flow = flow_from_clientsecrets('client_secrets.json',
                               scope='public_api',
                               redirect_uri='http://localhost:8080/')

credentials = storage.get()
if credentials == None:
    credentials = run(flow, storage, http=http)
    storage.put(credentials)

print "Your access_token is: %s" % credentials.access_token

http = credentials.authorize(http)

headers = {'Authorization': 'Bearer ' + credentials.access_token}

client = CmisClient('https://api.alfresco.com/cmis/versions/1.0/atom',
                    '',
                    '',
                    headers=headers)
repo = client.defaultRepository
print "cmislib connected to:"
print "    Name: %s" % repo.getRepositoryInfo()['repositoryId']
print "  Vendor: %s" % repo.getRepositoryInfo()['vendorName']