使用Google Directory API删除应用专用密码

时间:2017-04-06 20:58:31

标签: python google-api google-admin-sdk google-directory-api google-python-api

我已经为使用Google Directory API的用户编写了脚本/自动化整个终止流程(即更改密码,转移到其他OU等)这一切都很有效,但是,我注意到当我使用&时#34; Delete App Specific Password"称没有ASP实际被删除。当我在管理面板中签入时,它们仍然存在于用户帐户中。

我在脚本中执行了十几个其他Google API调用(这是有效的),所以,不,它不是权限/范围问题。在脚本的ASP部分期间不会抛出任何错误。它只是"处理"电话并继续。很奇怪。

当我在Google上使用Try this API部分时,它可以正常工作并删除我指定的ASP。

是否有其他人遇到此问题?

以下是相关代码的部分

scopes = ['https://www.googleapis.com/auth/admin.directory.user.security',
            'https://www.googleapis.com/auth/admin.directory.user',
            'https://www.googleapis.com/auth/gmail.settings.sharing',
            'https://www.googleapis.com/auth/gmail.modify',
            'https://www.googleapis.com/auth/admin.datatransfer',
            'https://www.googleapis.com/auth/admin.directory.group']

credentials = ServiceAccountCredentials.from_json_keyfile_name('../service-account-key.json', scopes=scopes)

delegated_credentials = credentials.create_delegated('REDACTED')
http_auth = delegated_credentials.authorize(Http())

directory_service = discovery.build('admin', 'directory_v1', http=http_auth)

def remove_asps():
    ##############################################################################################################################
    '''
    REMOVE ALL APP SPECIFIC PASSWORDS
    '''
    ##############################################################################################################################
    asp = directory_service.asps().list(userKey='{0}'.format(user_email)).execute()
    app_specific_passwords = asp.get('items', [])

    print('3) Removing App Specific Passwords:')
    if not app_specific_passwords:
        print('- {0} does not have any App Specific Passwords to remove.'.format(user_email))
        print('')
    else:
        for app_specific_password in app_specific_passwords:
            print('- Removing App Specific Password - {0} from {1}'.format(app_specific_password['name'],user_email))
            delete_asps = directory_service.asps().delete(userKey='{0}'.format(user_email),codeId='{0}'.format(app_specific_password['codeId']))
            print('Done.')
            print('')

我还尝试将值硬编码到调用中并删除for循环,而不是使用变量,这也不起作用。

日志显示调用已运行,但未引发任何错误:

googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/0?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/1?
googleapiclient.discovery: INFO     URL being requested: DELETE https://www.googleapis.com/admin/directory/v1/users/redacted_email/asps/2?

提前感谢您的帮助!

0 个答案:

没有答案