添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
率性的大熊猫  ·  Return Types In PHP - ...·  5 小时前    · 
慷慨大方的莲藕  ·  Strings·  5 小时前    · 
礼貌的小马驹  ·  SQL CONVERT ...·  8 小时前    · 
冷冷的牛排  ·  Solved: Rest api ...·  10 小时前    · 
淡定的鸡蛋  ·  SVG阴影滤镜 | WEB知识·  6 月前    · 
光明磊落的高山  ·  free fonts for ...·  11 月前    · 
public class Office365Authenticator implements Authenticator {
    private static final String DEFAULT_AUTHORITY = "https://login.windows.net/common/oauth2/authorize";
    private static final String DEFAULT_POWER_BI_RESOURCE_ID = "https://analysis.windows.net/powerbi/api";
    private static final boolean DEFAULT_VALIDATE_AUTHORITY = false;
    private String authority = DEFAULT_AUTHORITY;
    private String powerBiResourceId = DEFAULT_POWER_BI_RESOURCE_ID;
    private boolean validateAuthority = DEFAULT_VALIDATE_AUTHORITY;
    private String nativeClientId;
    private String tenant;
    private String username;
    private String password;
    private ExecutorService executor;
    private ReadWriteLock tokenLock = new ReentrantReadWriteLock();
    private String cachedToken;
    private String _authenticate() throws AuthenticationFailureException {
        try {
            AuthenticationContext authenticationContext = new AuthenticationContext(
                    authority,
                    validateAuthority,
                    executor
            String result = getAccessToken(
                    authenticationContext,
                    powerBiResourceId,
                    nativeClientId,
                    username + "@" + tenant,
                    password
            if (StringUtils.isEmpty(result)) {
                throw new AuthenticationFailureException("Returned access token is null.");
            return result;
        } catch (ExecutionException | InterruptedException | IOException e) {
            throw new AuthenticationFailureException(e);
    private String getAccessToken(AuthenticationContext authenticationContext, String resourceId, String clientId,
                                  String username, String password) throws ExecutionException, InterruptedException {
        return authenticationContext.acquireToken(
                resourceId,
                clientId,
                username,
                password,
        ).get().getAccessToken();

RESTful Java client with java.net.URL

Using REST in Java

Consuming REST services from Java applications

You could find more examples in Github.

public class Office365Authenticator implements Authenticator {
    private static final String DEFAULT_AUTHORITY = "https://login.windows.net/common/oauth2/authorize";
    private static final String DEFAULT_POWER_BI_RESOURCE_ID = "https://analysis.windows.net/powerbi/api";
    private static final boolean DEFAULT_VALIDATE_AUTHORITY = false;
    private String authority = DEFAULT_AUTHORITY;
    private String powerBiResourceId = DEFAULT_POWER_BI_RESOURCE_ID;
    private boolean validateAuthority = DEFAULT_VALIDATE_AUTHORITY;
    private String nativeClientId;
    private String tenant;
    private String username;
    private String password;
    private ExecutorService executor;
    private ReadWriteLock tokenLock = new ReentrantReadWriteLock();
    private String cachedToken;
    private String _authenticate() throws AuthenticationFailureException {
        try {
            AuthenticationContext authenticationContext = new AuthenticationContext(
                    authority,
                    validateAuthority,
                    executor
            String result = getAccessToken(
                    authenticationContext,
                    powerBiResourceId,
                    nativeClientId,
                    username + "@" + tenant,
                    password
            if (StringUtils.isEmpty(result)) {
                throw new AuthenticationFailureException("Returned access token is null.");
            return result;
        } catch (ExecutionException | InterruptedException | IOException e) {
            throw new AuthenticationFailureException(e);
    private String getAccessToken(AuthenticationContext authenticationContext, String resourceId, String clientId,
                                  String username, String password) throws ExecutionException, InterruptedException {
        return authenticationContext.acquireToken(
                resourceId,
                clientId,
                username,
                password,
        ).get().getAccessToken();
						

@Eric_Zhang
In this code snippet   

authority, validateAuthority, executor (authenticationContext )? - How should i fill these values? what do they means ?

powerBiResourceId? - Where is this id , what does it means?
nativeClientId - I'm making a web app (not native app) and this will be ApplicationId in  Azure? 
username + "@" + tenant - I know this
password - I know this

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.