获取不到username,Scope不支持默认修改

authing-java-sdk
3.1.4

username

使用id-token进行解析,始终都没有 username 字段

scope

默认设置AuthenticationClientOptions不起作用,始终都是默认的权限

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public AuthenticationClient authenticationClient() throws IOException, ParseException, ParseException {
        //在构造函数中分别填入自己的 App ID、App Secret、APP Host。
        AuthenticationClientOptions options = new AuthenticationClientOptions();
        options.setAppId(YOUR_APP_ID); // 改成自己的 App ID
        options.setAppSecret(YOUR_APP_SECRET); // 改成自己的  App Secret
        options.setAppHost(YOUR_APP_HOST); // 设置自己的认证地址
//        options.setRedirectUri("http://localhost:16800/callback"); // 填写之前设置的回调地址
//        options.setProtocol(ProtocolEnum.OIDC.getValue());
        // https://docs.authing.cn/v2/concepts/oidc-common-questions.html
        options.setScope("openid profile offline_access username phone external_id extended_fields");
        return new AuthenticationClient(options);
    }

在登录接口设置之后,每次都需要页面授权

    @GetMapping("/login")
    public String login() {
        IOidcParams iOidcParams = new IOidcParams();
        iOidcParams.setRedirectUri("http://localhost:16800/callback");
        // 此处权限要在默认权限后用空格分隔,添加
//        iOidcParams.setScope("openid profile email phone address ecs:Start");
        // https://docs.authing.cn/v2/concepts/oidc-common-questions.html
        iOidcParams.setScope("openid profile offline_access username phone external_id extended_fields");
        return "redirect:" + authClientFactory.getObject().buildAuthorizeUrl(iOidcParams);
    }
    public static void buildUrl() throws Exception {
        AuthenticationClient client = authenticationClient();
        IOidcParams iOidcParams = new IOidcParams();
        iOidcParams.setRedirectUri("http://localhost:16800/callback");
        // 此处权限要在默认权限后用空格分隔,添加
        //        iOidcParams.setScope("openid profile email phone address ecs:Start");
        // https://docs.authing.cn/v2/concepts/oidc-common-questions.html
        iOidcParams.setScope("openid profile username phone external_id extended_fields");
        String url = client.buildAuthorizeUrl(iOidcParams);
        System.out.println(url);
    }

    public static void getTokenByCode() throws Exception {
        String code = "O7Jg4VgDnb3sc7pywVnxMIKO8eX8nBFsS_k6X-TrJZL";
        OIDCTokenResponse accessTokenByCode = client.getAccessTokenByCode(code);
        System.out.println(accessTokenByCode);
        System.out.println(accessTokenByCode.getIdToken());
    }

    public static AuthenticationClient authenticationClient() throws IOException, ParseException, ParseException {
        //在构造函数中分别填入自己的 App ID、App Secret、APP Host。
        AuthenticationClientOptions options = new AuthenticationClientOptions();
        options.setAppId(YOUR_APP_ID); // 改成自己的 App ID
        options.setAppSecret(YOUR_APP_SECRET); // 改成自己的  App Secret
        options.setAppHost(YOUR_APP_HOST); // 设置自己的认证地址
        //        options.setRedirectUri("http://localhost:16800/callback"); // 填写之前设置的回调地址
        //        options.setProtocol(ProtocolEnum.OIDC.getValue());
        // https://docs.authing.cn/v2/concepts/oidc-common-questions.html
        options.setScope("openid profile username phone external_id extended_fields");
        options.setRedirectUri("http://localhost:16800/callback");
        return new AuthenticationClient(options);
    }
  1. scope 中有 username, 生成的 idtoken 中会包含 username

  1. 默认设置AuthenticationClientOptions不起作用,始终都是默认的权限:

确实是这样,后续升级 sdk 会做修复,感谢指出,辛苦您在 IOidcParams 中重新设置下 scope 了

  1. 在登录接口设置之后,每次都需要页面授权

scope 包含了 offline_access 时,默认是会展示授权确认页

好的,了解了,我修改一下