PowerBI 대시 보드를 고객 MVC 포털에 포함하려고합니다. 고객은 AAD 계정이 없으므로 웹 사이트에 올 때 Live에 로그인 할 수 없으므로 개별 권한으로 MVC 웹 사이트에 로그인합니다.PowerBI 및 Azure AD 헤드리스 로그인
PowerBI/AAD에 내 App을 등록하고 ClientID와 Secret을 가지고 있습니다. 나는 AAD에 전화를 걸어 인증 코드를 얻는다.이 코드를 사용하여 성공적으로 반환되는 인증 토큰을 얻는다.
액세스 토큰을 사용하여 대시 보드를 얻었을 때 403 금지됨과 함께 계속 거부됩니다.
Microsoft의 모든 샘플을 살펴 보았으나 사용자 로그인 프롬프트가 필요합니다. AcquireToken 메서드를 참조하는 ADAL2.0 코드를 검토했지만 ADAL3에서는 더 이상 사용되지 않으며 다른 매개 변수가있는 AcquireTokenAsync로 바뀌었고 아래 예제에서이 코드를 사용하고 있습니다.
protected AuthenticationResult GetAccessToken()
{
string pBiUser = Properties.Settings.Default.PowerBIUser;
string pBiPwd = Properties.Settings.Default.PowerBIPwd;
string pBiClientId = Properties.Settings.Default.PowerBIClientId;
string pBiSecret = Properties.Settings.Default.PowerBIClientSecret;
TokenCache TC = new TokenCache();
ClientCredential CC = new ClientCredential(pBiClientId,pBiSecret);
string AU = Properties.Settings.Default.PowerBIAuthority;
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authenticationContext
= new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(AU, TC);
AuthenticationResult result = authenticationContext.AcquireTokenAsync("https://analysis.windows.net/powerbi/api"
,CC).Result;
if (result == null)
{
throw new InvalidOperationException("Failed to obtain the PowerBI token");
}
return result;
}
내가 다음 토큰 결과를 가지고 전화 : 여기
는 토큰을 얻을 수있는 기능입니다. 응답 수신 403 : 에러 메시지 (403
) 기준
protected PBIDashboards GetDashboards(AuthenticationResult authResult)
{
PBIDashboards pbiDashboards = new PBIDashboards();
var baseAddress = new Uri("https://api.powerbi.com");
using (var httpClient = new System.Net.Http.HttpClient {BaseAddress = baseAddress})
{
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("authorization",
"Bearer " + authResult.AccessToken);
using (**var response** = httpClient.GetAsync("v1.0/myorg/dashboards").Result)
{
string responseData = response.Content.ReadAsStringAsync().Result;
//Deserialize JSON string
pbiDashboards = JsonConvert.DeserializeObject<PBIDashboards>(responseData);
if (pbiDashboards != null)
{
var gridViewDashboards = pbiDashboards.value.Select(dashboard => new
{
Id = dashboard.id,
DisplayName = dashboard.displayName,
EmbedUrl = dashboard.embedUrl
});
}
}
}
return pbiDashboards;
}
여기서 정확한 질문은 무엇입니까? 사용자 인터페이스없이 사용자를 로그인하는 방법을 찾고 있습니까? –