测试 Python 应用程序

在该解决方案的这一部分中,您可以注册示例 Python Web 应用程序,将其与Oracle Identity Cloud Service集成在一起,设置应用程序以使其使用Oracle Identity Cloud Service的 SDK(适用于 Python),并准备、运行和测试应用程序。

注册 Python 应用程序

要与Oracle Identity Cloud Service建立通信,示例 Web 应用程序需要客户机 ID 和客户机密钥。您还需要配置 API 权限以授予示例 Web 应用程序。

要将示例 Web 应用程序注册到Oracle Identity Cloud Service,请执行以下操作:

  1. 在Identity Cloud Service控制台中,展开导航提取器,然后单击应用程序
  2. In the Applications page, click Add.
  3. 添加应用程序 选择器对话框中,单击可信应用程序
  4. In the Name and Description fields of the Details pane, enter SDK Web Application, and then click Next.
  5. 客户机 窗格中,选择立即将此应用程序配置为客户机,然后填充此窗格的字段,如下所示:

    表- “客户机”窗格

    字段
    允许的授权类型 选择客户机身份证明授权代码
    允许非 Https URLs 选中此复选框。该示例应用程序在非 Https 模式下工作。
    重定向 URL http://localhost:8000/callback
    注销 URL http://localhost:8000/logout
    发布注销重定向 URL http://localhost:8000
  6. 客户端 窗格中向下滚动,选择向下授予对Identity Cloud Service管理APIs的客户端访问权限。在下面的字段中输入Me,然后单击下一步
  7. 在以下窗格上,单击下一步 直到到达最后一个窗格。然后,单击完成
  8. 添加的应用程序 对话框中,记录客户机 ID客户机密钥 值,然后单击关闭。Web 应用程序需要这些值才能与Oracle Identity Cloud Service集成。
  9. 要激活应用程序,请单击激活
  10. 激活应用程序? 对话框中,单击激活应用程序

    成功消息会激活 SDK Web 应用程序。此时将 显示。

  11. 在Identity Cloud Service控制台中,单击屏幕右上角的用户名,然后单击注销

设置 Python 应用程序

要设置示例应用程序代码以使其使用Oracle Identity Cloud Service的 SDK 进行 Python 编程语言:

  1. 使用以下内容更新c:\temp\python\config.json文件:
    {
     "ClientId" : "123456789abcdefghij", 
     "ClientSecret" : "abcde-12345-zyxvu-98765-qwerty", 
     "BaseUrl" : "https://idcs-abcd1234.identity.oraclecloud.com", 
     "AudienceServiceUrl" : "https://idcs-abcd1234.identity.oraclecloud.com",
      "scope" : "urn:opc:idm:t.user.me openid",
      "TokenIssuer" : "https://identity.oraclecloud.com",
      "redirectURL": "http://localhost:8000/callback",
      "logoutSufix":"/oauth2/v1/userlogout"
    }
  2. 保存config.json文件。

运行 Python 应用程序

要准备、运行和测试示例 Web 应用程序:

  1. 打开命令提示符并导航到c:\temp\python文件夹。
  2. 在命令提示符下,输入python.exe manage.py migrate以准备示例应用程序,然后运行命令行python manage.py runserver以启动该应用程序。

    Python 服务器使用8000端口。请确保该端口未由其他服务使用。

  3. 打开浏览器窗口,访问http://localhost:8000 URL,然后单击登录
  4. In the Login page, click the Oracle red icon, which appears to the right of or You can log in with.

    The sample application's login form (the Email and Password fields, and the Log In button) doesn’t work. It’s illustrative only.

  5. 在Oracle Identity Cloud Service登录 页中,使用Oracle Identity Cloud Service身份证明登录。

    在您成功登录到Oracle Identity Cloud Service之后,浏览器将重定向到/home 页。登录用户的名称显示在右上角。

  6. 在左菜单中,单击我的概要文件
  7. 确保与您的概要文件关联的信息显示在页的中央。