public void CanCreateReportEmbedTokenWithScopesList()
        {
            var workspaceId = Guid.NewGuid().ToString();
            var reportId    = Guid.NewGuid().ToString();
            var scopesList  = new List <string>()
            {
                Scopes.DatasetRead,
                Scopes.ReportReadWrite
            };

            var token = PowerBIToken.CreateReportEmbedTokenWithScopes("Contoso", workspaceId, reportId, scopesList: scopesList);

            Assert.IsNotNull(token);
            var jwt = token.Generate(this.accessKey);

            Assert.IsFalse(string.IsNullOrEmpty(jwt));

            var decodedToken = new JwtSecurityToken(jwt);

            var scopesClaim = decodedToken.Claims.FirstOrDefault(c => c.Type == PowerBIToken.ClaimTypes.Scopes).Value.Split(' ').ToList();

            foreach (var scope in scopesList)
            {
                Assert.IsTrue(scopesClaim.Contains(scope));
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                List <PowerBiModel> reportsList = new List <PowerBiModel>();
                var devToken = PowerBIToken.CreateReportEmbedTokenWithScopes(workspaceCollection, workspaceId);
                using (var client = this.CreatePowerBIClient(devToken))
                {
                    var reportsResponse = client.Reports.GetReports(workspaceCollection, workspaceId);

                    for (int i = 0; i < reportsResponse.Value.ToList().Count; i++)
                    {
                        reportsList.Add(new PowerBiModel
                        {
                            Id       = reportsResponse.Value[i].Id,
                            Name     = reportsResponse.Value[i].Name,
                            EmbedUrl = reportsResponse.Value[i].EmbedUrl,
                            WebUrl   = reportsResponse.Value[i].WebUrl,
                            //Report = reportsResponse.Value[i].
                        }
                                        );
                    }
                }

                var reportId = reportsList[0].Id;
                using (var client = this.CreatePowerBIClient(devToken))
                {
                    var embedToken = PowerBIToken.CreateReportEmbedToken(workspaceCollection, workspaceId, reportId);

                    var viewModel = new PowerBiModel
                    {
                        Report      = reportsList[0].Report,
                        AccessToken = embedToken.Generate(accessKey)
                    };

                    accessTokenText.Value = viewModel.AccessToken;
                    embedUrlText.Value    = viewModel.EmbedUrl;
                }
            }
        }