Skip to content

Commit

Permalink
Merged PR 239856: [Developer Samples]: Update reference to environmen…
Browse files Browse the repository at this point in the history
…t variables

Related work items: #766862, #769896
  • Loading branch information
bapat-atharva committed Mar 29, 2022
1 parent 0d36b89 commit c25608d
Show file tree
Hide file tree
Showing 32 changed files with 71 additions and 39 deletions.
@@ -1,5 +1,6 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.com/"
"AuthorityUrl": "https://login.microsoftonline.com/",
"Scopes": ["https://analysis.windows.net/powerbi/api/Report.Read.All https://analysis.windows.net/powerbi/api/Dashboard.Read.All https://analysis.windows.net/powerbi/api/Workspace.Read.All"]
}
}
@@ -1,5 +1,6 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.com/"
"AuthorityUrl": "https://login.microsoftonline.com/",
"Scopes": ["https://analysis.usgovcloudapi.net/powerbi/api/Report.Read.All https://analysis.usgovcloudapi.net/powerbi/api/Dashboard.Read.All https://analysis.usgovcloudapi.net/powerbi/api/Workspace.Read.All"]
}
}
@@ -1,5 +1,6 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.de/"
"AuthorityUrl": "https://login.microsoftonline.de/",
"Scopes": ["https://analysis.cloudapi.de/powerbi/api/Report.Read.All https://analysis.cloudapi.de/powerbi/api/Dashboard.Read.All https://analysis.cloudapi.de/powerbi/api/Workspace.Read.All"]
}
}
@@ -1,5 +1,6 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.chinacloudapi.cn/"
"AuthorityUrl": "https://login.chinacloudapi.cn/",
"Scopes": ["https://analysis.chinacloudapi.cn/powerbi/api/Report.Read.All https://analysis.chinacloudapi.cn/powerbi/api/Dashboard.Read.All https://analysis.chinacloudapi.cn/powerbi/api/Workspace.Read.All"]
}
}
Expand Up @@ -5,9 +5,9 @@

namespace UserOwnsData.Controllers
{
using UserOwnsData.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Identity.Web;
using Microsoft.Graph;
using System.Threading.Tasks;
Expand All @@ -20,11 +20,15 @@ public class HomeController : Controller

private readonly ITokenAcquisition m_tokenAcquisition;

public IConfiguration Configuration { get; }

public HomeController(ITokenAcquisition tokenAcquisition,
GraphServiceClient graphServiceClient)
GraphServiceClient graphServiceClient,
IConfiguration configuration)
{
this.m_tokenAcquisition = tokenAcquisition;
this.m_graphServiceClient = graphServiceClient;
Configuration = configuration;
}

[AllowAnonymous]
Expand All @@ -34,11 +38,11 @@ public IActionResult Index()
}

// Redirects to login page to request increment consent
[AuthorizeForScopes(ScopeBase = new string[] { PowerBiScopes.ReadDashboard, PowerBiScopes.ReadReport, PowerBiScopes.ReadWorkspace })]
[AuthorizeForScopes(ScopeKeySection = "AzureAd:Scopes")]
public async Task<IActionResult> Embed()
{
// Generate token for the signed in user
var accessToken = await m_tokenAcquisition.GetAccessTokenForUserAsync(new string[] { PowerBiScopes.ReadDashboard, PowerBiScopes.ReadReport, PowerBiScopes.ReadWorkspace });
var accessToken = await m_tokenAcquisition.GetAccessTokenForUserAsync(Configuration["AzureAd:Scopes:0"].Split(" "));

// Get username of logged in user
var userInfo = await m_graphServiceClient.Me.Request().GetAsync();
Expand Down

This file was deleted.

Expand Up @@ -5,7 +5,6 @@

namespace UserOwnsData
{
using UserOwnsData.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -21,6 +20,7 @@ public class Startup
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Configuration["AzureAd:Instance"] = Configuration["AzureAd:AuthorityUrl"];
}

public IConfiguration Configuration { get; }
Expand Down
@@ -1,8 +1,10 @@
{
"AzureAd": {
"Instance": "",
"AuthorityUrl": "https://login.microsoftonline.com/",
"Domain": "",
"TenantId": "common",
"Scopes": ["https://analysis.windows.net/powerbi/api/Report.Read.All https://analysis.windows.net/powerbi/api/Dashboard.Read.All https://analysis.windows.net/powerbi/api/Workspace.Read.All"],
"ClientId": "",
"ClientSecret": "",
"CallbackPath": "/signin-oidc"
Expand Down
@@ -1,6 +1,7 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.com/organizations/",
"PowerBiApiUrl": "https://api.powerbi.com/",
"ScopeBase": ["https://analysis.windows.net/powerbi/api/.default"]
}
}
@@ -1,6 +1,7 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.com/organizations/",
"PowerBiApiUrl": "https://api.powerbigov.us/",
"ScopeBase": ["https://analysis.usgovcloudapi.net/powerbi/api/.default"]
}
}
@@ -1,6 +1,7 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.microsoftonline.de/organizations/",
"PowerBiApiUrl": "https://api.powerbi.de/",
"ScopeBase": ["https://analysis.cloudapi.de/powerbi/api/.default"]
}
}
@@ -1,6 +1,7 @@
{
"AzureAd": {
"AuthorityUrl": "https://login.chinacloudapi.cn/organizations/",
"PowerBiApiUrl": "https://api.powerbi.cn/",
"ScopeBase": ["https://analysis.chinacloudapi.cn/powerbi/api/.default"]
}
}
Expand Up @@ -19,6 +19,9 @@ public class AzureAd
// Id of the Azure tenant in which AAD app is hosted. Required only for Service Principal authentication mode.
public string TenantId { get; set; }

// End point URL for REST API
public string PowerBiApiUrl { get; set; }

// ScopeBase of AAD app. Use the below configuration to use all the permissions provided in the AAD app through Azure portal.
public string[] ScopeBase { get; set; }

Expand Down
Expand Up @@ -67,5 +67,9 @@ public string GetAccessToken()

return authenticationResult.AccessToken;
}

public string GetPowerBiApiUrl() {
return azureAd.Value.PowerBiApiUrl;
}
}
}
Expand Up @@ -16,7 +16,6 @@ namespace EncryptCredentials.Services
public class PowerBIService
{
private readonly AadService aadService;
private readonly string powerBiApiUrl = "https://api.powerbi.com";

public PowerBIService(AadService aadService)
{
Expand All @@ -30,7 +29,7 @@ public PowerBIService(AadService aadService)
public PowerBIClient GetPowerBIClient()
{
var tokenCredentials = new TokenCredentials(aadService.GetAccessToken(), "Bearer");
return new PowerBIClient(new Uri(powerBiApiUrl), tokenCredentials);
return new PowerBIClient(new Uri(aadService.GetPowerBiApiUrl()), tokenCredentials);
}

/// <summary>
Expand Down
Expand Up @@ -4,6 +4,7 @@
"AuthorityUrl": "https://login.microsoftonline.com/organizations/",
"ClientId": "",
"TenantId": "",
"PowerBiApiUrl": "https://api.powerbi.com/",
"ScopeBase": ["https://analysis.windows.net/powerbi/api/.default"],
"RedirectUri": "http://localhost:5001/",
"PbiUsername": "",
Expand Down
Expand Up @@ -8,5 +8,6 @@
public abstract class Config {

public static final String authorityUrl = "https://login.microsoftonline.com/";
public static final String powerBiApiUrl = "https://api.powerbi.com/";
public static final String scopeBase = "https://analysis.windows.net/powerbi/api/.default";
}
Expand Up @@ -8,5 +8,6 @@
public abstract class Config {

public static final String authorityUrl = "https://login.microsoftonline.com/";
public static final String powerBiApiUrl = "https://api.powerbigov.us/";
public static final String scopeBase = "https://analysis.usgovcloudapi.net/powerbi/api/.default";
}
Expand Up @@ -8,5 +8,6 @@
public abstract class Config {

public static final String authorityUrl = "https://login.microsoftonline.de/";
public static final String powerBiApiUrl = "https://api.powerbi.de/";
public static final String scopeBase = "https://analysis.cloudapi.de/powerbi/api/.default";
}
Expand Up @@ -8,5 +8,6 @@
public abstract class Config {

public static final String authorityUrl = "https://login.chinacloudapi.cn/";
public static final String powerBiApiUrl = "https://api.powerbi.cn/";
public static final String scopeBase = "https://analysis.chinacloudapi.cn/powerbi/api/.default";
}
Expand Up @@ -35,6 +35,7 @@ public abstract class Config {

// DO NOT CHANGE
public static final String authorityUrl = "https://login.microsoftonline.com/";
public static final String powerBiApiUrl = "https://api.powerbi.com/";
public static final String scopeBase = "https://analysis.windows.net/powerbi/api/.default";

private Config() {
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import com.encryptcredentialsample.encryptcredential.config.Config;
import com.encryptcredentialsample.encryptcredential.models.CredentialDetails;
import com.encryptcredentialsample.encryptcredential.models.GatewayPublicKey;
import com.encryptcredentialsample.encryptcredential.models.PublishDatasourceToGatewayRequest;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static ResponseEntity<String> addDataSource(
public static ResponseEntity<String> makeAddDataSourcePostRequest(String gatewayId, PublishDatasourceToGatewayRequest requestBody, String accessToken) throws ClientProtocolException, IOException {
// Gateways - Create Datasource Power BI REST API
// https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource
String endPointUrl = "https://api.powerbi.com/v1.0/myorg/gateways/" + gatewayId + "/datasources";
String endPointUrl = Config.powerBiApiUrl + "v1.0/myorg/gateways/" + gatewayId + "/datasources";

// Request header
HttpHeaders reqHeader = Utils.generateAuthorizationHeaders(accessToken);
Expand Down
Expand Up @@ -13,15 +13,16 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import com.encryptcredentialsample.encryptcredential.config.Config;
import com.encryptcredentialsample.encryptcredential.models.Gateway;
import com.encryptcredentialsample.encryptcredential.models.GetDatasourcesResponse;

public class GetDatasourceData {

public static Gateway getGateway(String accessToken, String getwayId) {
public static Gateway getGateway(String accessToken, String gatewayId) {

// REST API URL to get data sources
String endPointUrl = "https://api.powerbi.com/v1.0/myorg/gateways/" + getwayId;
String endPointUrl = Config.powerBiApiUrl + "v1.0/myorg/gateways/" + gatewayId;

// Request header
HttpHeaders reqHeader = new HttpHeaders();
Expand Down Expand Up @@ -49,7 +50,7 @@ public static GetDatasourcesResponse getDatasourcesInGroup(String accessToken, S
HttpEntity<String> reqEntity = new HttpEntity<>(reqHeader);

// https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/getdatasourcesingroup
String endPointUrl = "https://api.powerbi.com/v1.0/myorg/groups/" + groupId + "/datasets/" + datasetId + "/datasources";
String endPointUrl = Config.powerBiApiUrl + "v1.0/myorg/groups/" + groupId + "/datasets/" + datasetId + "/datasources";

// Rest API get datasources's details
RestTemplate getDatasourceRestTemplate = new RestTemplate();
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import com.encryptcredentialsample.encryptcredential.config.Config;
import com.encryptcredentialsample.encryptcredential.models.CredentialDetails;
import com.encryptcredentialsample.encryptcredential.models.CredentialDetailsRequestBody;
import com.encryptcredentialsample.encryptcredential.models.Gateway;
Expand Down Expand Up @@ -77,7 +78,7 @@ public static ResponseEntity<String> makeUpdateDataSourcePatchRequest(

// Gateways - Update Datasource Power BI REST API
// https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource
String endPointUrl = "https://api.powerbi.com/v1.0/myorg/gateways/" + gatewayId + "/datasources/" + datasourceId;
String endPointUrl = Config.powerBiApiUrl + "v1.0/myorg/gateways/" + gatewayId + "/datasources/" + datasourceId;

// Request header
HttpHeaders reqHeader = Utils.generateAuthorizationHeaders(accessToken);
Expand Down
Expand Up @@ -9,4 +9,7 @@ class BaseConfig(object):
SCOPE_BASE = ['https://analysis.windows.net/powerbi/api/.default']

# URL used for initiating authorization request
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'

# End point URL for Power BI API
POWER_BI_API_URL = 'https://api.powerbi.com/'
Expand Up @@ -9,4 +9,7 @@ class BaseConfig(object):
SCOPE_BASE = ['https://analysis.usgovcloudapi.net/powerbi/api/.default']

# URL used for initiating authorization request
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'

# End point URL for Power BI API
POWER_BI_API_URL = 'https://api.powerbigov.us/'
Expand Up @@ -9,4 +9,7 @@ class BaseConfig(object):
SCOPE_BASE = ['https://analysis.cloudapi.de/powerbi/api/.default']

# URL used for initiating authorization request
AUTHORITY_URL = 'https://login.microsoftonline.de/organizations'
AUTHORITY_URL = 'https://login.microsoftonline.de/organizations'

# End point URL for Power BI API
POWER_BI_API_URL = 'https://api.powerbi.de/'
Expand Up @@ -9,4 +9,7 @@ class BaseConfig(object):
SCOPE_BASE = ['https://analysis.chinacloudapi.cn/powerbi/api/.default']

# URL used for initiating authorization request
AUTHORITY_URL = 'https://login.chinacloudapi.cn/organizations'
AUTHORITY_URL = 'https://login.chinacloudapi.cn/organizations'

# End point URL for Power BI API
POWER_BI_API_URL = 'https://api.powerbi.cn/'
3 changes: 3 additions & 0 deletions Python/Encrypt credentials/Encryption sample/config.py
Expand Up @@ -21,6 +21,9 @@ class BaseConfig(object):
# URL used for initiating authorization request
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'

# End point URL for Power BI API
POWER_BI_API_URL = 'https://api.powerbi.com/'

# Master user email address. Required only for MasterUser authentication mode.
POWER_BI_USER = ''

Expand Down
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT license.

import requests
from flask import current_app as app
from flask import json
from models.credentialsdetails import CredentialsDetails
from models.publishdatasourcetogatewayrequest import PublishDatasourceToGatewayRequest
Expand Down Expand Up @@ -65,7 +66,7 @@ def make_add_datasource_post_request(self, gateway_id, request_body, access_toke

# Gateways - Create Datasource Power BI REST API
# https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource
endpoint_url = f'https://api.powerbi.com/v1.0/myorg/gateways/{gateway_id}/datasources'
endpoint_url = f'{app.config["POWER_BI_API_URL"]}v1.0/myorg/gateways/{gateway_id}/datasources'

api_response = requests.post(endpoint_url, data=json.dumps(request_body.__dict__), headers=self.headers)

Expand Down

0 comments on commit c25608d

Please sign in to comment.