コード例 #1
0
ファイル: outlook.py プロジェクト: olofster/inbox
    def create_account(self, db_session, email_address, response):
        email_address = response.get('emails')['account']
        try:
            account = db_session.query(OutlookAccount).filter_by(
                email_address=email_address).one()
        except sqlalchemy.orm.exc.NoResultFound:
            namespace = Namespace()
            account = OutlookAccount(namespace=namespace)

        account.refresh_token = response['refresh_token']
        account.date = datetime.datetime.utcnow()
        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.o_id_token = response.get('user_id')
        account.o_id = response.get('id')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.link = response.get('link')
        account.locale = response.get('locale')

        # Hack to ensure that account syncs get restarted if they were stopped
        # because of e.g. invalid credentials and the user re-auths.
        # TODO(emfree): remove after status overhaul.
        if account.sync_state != 'running':
            account.sync_state = None

        return account
コード例 #2
0
ファイル: _outlook.py プロジェクト: rf-/sync-engine
    def create_account(self, db_session, email_address, response):
        email_address = response.get('emails')['account']
        try:
            account = db_session.query(OutlookAccount).filter_by(
                email_address=email_address).one()
        except sqlalchemy.orm.exc.NoResultFound:
            namespace = Namespace()
            account = OutlookAccount(namespace=namespace)

        account.refresh_token = response['refresh_token']
        account.date = datetime.datetime.utcnow()
        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.o_id_token = response.get('user_id')
        account.o_id = response.get('id')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.link = response.get('link')
        account.locale = response.get('locale')

        # Unlike Gmail, Outlook doesn't return the client_id and secret here
        account.client_id = OAUTH_CLIENT_ID
        account.client_secret = OAUTH_CLIENT_SECRET

        # Ensure account has sync enabled.
        account.enable_sync()

        return account
コード例 #3
0
    def create_account(self, db_session, email_address, response):
        email_address = response.get('emails')['account']
        try:
            account = db_session.query(OutlookAccount).filter_by(
                email_address=email_address).one()
        except sqlalchemy.orm.exc.NoResultFound:
            namespace = Namespace()
            account = OutlookAccount(namespace=namespace)

        account.refresh_token = response['refresh_token']
        account.date = datetime.datetime.utcnow()
        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.o_id_token = response.get('user_id')
        account.o_id = response.get('id')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.link = response.get('link')
        account.locale = response.get('locale')

        # Ensure account has sync enabled.
        account.enable_sync()

        return account
コード例 #4
0
ファイル: outlook.py プロジェクト: apolmig/inbox
    def create_account(self, db_session, email_address, response):
        email_address = response.get('emails')['account']
        try:
            account = db_session.query(OutlookAccount).filter_by(
                email_address=email_address).one()
        except sqlalchemy.orm.exc.NoResultFound:
            namespace = Namespace()
            account = OutlookAccount(namespace=namespace)

        account.refresh_token = response['refresh_token']
        account.date = datetime.datetime.utcnow()
        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.o_id_token = response.get('user_id')
        account.o_id = response.get('id')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.link = response.get('link')
        account.locale = response.get('locale')

        # Hack to ensure that account syncs get restarted if they were stopped
        # because of e.g. invalid credentials and the user re-auths.
        # TODO(emfree): remove after status overhaul.
        if account.sync_state != 'running':
            account.sync_state = None

        return account
コード例 #5
0
ファイル: gmail.py プロジェクト: olofster/inbox
    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if not account.refresh_token or account.sync_state == 'invalid':
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the one we have doesn't work.)
                raise OAuthError("Missing refresh token")

        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.g_id_token = response.get('id_token')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.sync_contacts = response.get('contacts', True)
        account.sync_events = response.get('events', True)

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            raise UserRecoverableConfigError(e)

        # Hack to ensure that account syncs get restarted if they were stopped
        # because of e.g. invalid credentials and the user re-auths.
        # TODO(emfree): remove after status overhaul.
        if account.sync_state != 'running':
            account.sync_state = None

        return account
コード例 #6
0
    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if not account.refresh_token or account.sync_state == 'invalid':
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the one we have doesn't work.)
                raise OAuthError("Missing refresh token")

        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.g_id_token = response.get('id_token')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.sync_contacts = response.get('contacts', True)
        account.sync_events = response.get('events', True)

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            raise UserRecoverableConfigError(e)

        # Ensure account has sync enabled.
        account.enable_sync()

        # See if we've already stored this refresh token
        match = [auth_creds for auth_creds in account.auth_credentials
                 if auth_creds.refresh_token == new_refresh_token]

        # For new refresh_tokens, create new GmailAuthCredentials entry
        if new_refresh_token and len(match) == 0:
            auth_creds = GmailAuthCredentials()
            auth_creds.gmailaccount = account
            auth_creds.scopes = response.get('scope')
            auth_creds.g_id_token = response.get('id_token')
            auth_creds.client_id = response.get('client_id')
            auth_creds.client_secret = response.get('client_secret')
            auth_creds.refresh_token = new_refresh_token

        return account
コード例 #7
0
    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if not account.refresh_token or account.sync_state == 'invalid':
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the one we have doesn't work.)
                raise OAuthError("Missing refresh token")

        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.g_id_token = response.get('id_token')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.sync_contacts = response.get('contacts', True)
        account.sync_events = response.get('events', True)

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            raise UserRecoverableConfigError(e)

        # Ensure account has sync enabled.
        account.enable_sync()

        # See if we've already stored this refresh token
        match = [
            auth_creds for auth_creds in account.auth_credentials
            if auth_creds.refresh_token == new_refresh_token
        ]

        # For new refresh_tokens, create new GmailAuthCredentials entry
        if new_refresh_token and len(match) == 0:
            auth_creds = GmailAuthCredentials()
            auth_creds.gmailaccount = account
            auth_creds.scopes = response.get('scope')
            auth_creds.g_id_token = response.get('id_token')
            auth_creds.client_id = response.get('client_id')
            auth_creds.client_secret = response.get('client_secret')
            auth_creds.refresh_token = new_refresh_token

        return account