C# AAD中此请求的授权已被拒绝
我是Azure Active Directory开发的新手。我们几乎没有需要web应用程序和移动设备(基于cordova的应用程序)访问的服务C# AAD中此请求的授权已被拒绝,c#,cordova,azure,windows-phone-8.1,C#,Cordova,Azure,Windows Phone 8.1,我是Azure Active Directory开发的新手。我们几乎没有需要web应用程序和移动设备(基于cordova的应用程序)访问的服务 对于我们正在使用的Web应用程序 对于我们正在使用的移动应用程序 问题 使用ADAL JS生成的令牌通过web服务进行授权,并按预期工作。但是使用Azure AD生成的令牌抛出了相应的错误 此请求的授权已被拒绝 变通办法 我们试图使用C#中的用户凭据获取访问令牌。我们成功地实现了这一目标。使用那个访问令牌,我们试图在Fiddler中访问我们的服务。即
- 对于我们正在使用的Web应用程序
- 对于我们正在使用的移动应用程序
var authority = 'https://login.windows.net/**tenantName**';
var resourceUrl = 'https://graph.windows.net/';
var clientID = '***CLIENT ID IN NATIVE APP***';
var redirectUrl = 'http://localhost:49906/';
var tenantName = '***TENANT NAME***';
var endpointUrl = resourceUrl + tenantName;
createContext: function () {
AuthenticationContext.createAsync(authority)
.then(function (context) {
mapp.authContext = context;
mapp.log("Created authentication context for authority URL: " + context.authority);
mapp.acquireToken();
}, mapp.error);
},
acquireToken: function () {
if (mapp.authContext == null) {
mapp.error('Authentication context isn\'t created yet. Create context first');
return;
}
mapp.authContext.acquireTokenSilentAsync(resourceUrl, clientID).then(function (success) {
console.log("INSIDESILENT");
mapp.error("Failed to acquire token: " + success);
console.log("DATA:::: "+success);
}, function () {
mapp.authContext.acquireTokenAsync(resourceUrl, clientID, redirectUrl)
.then(function (authResult) {
mapp.log('Acquired token successfully: ' + pre(authResult));
console.log("DATA:::"+authResult.accessToken);
localStorage.setItem("SSOFlag", "true");
angular.bootstrap(document, ['keurapp']);
userDetail = JSON.parse(localStorage.getItem("userDetails"));
}, function (err) {
mapp.error("Failed to acquire token: " + pre(err));
});
});
}
C#代码
服务样本:
//[EnableCors(origins: "*", headers: "*", methods: "*")]
//[Authorize]
public class RepositoryController : ApiController
{
//With Few methods
}
public void Configuration(IAppBuilder app)
{
ConfigureOAuth(app);
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
}
正在查找帮助您用于AAD、Graph API等的nuget软件包和版本是什么?@juvchan这些nuget软件包版本我们使用的是Microsoft.IdentityModel.Clients.ActiveDirectory V2.19、Microsoft.Azure.ActiveDirectory.GraphClient V2.1.0
//[EnableCors(origins: "*", headers: "*", methods: "*")]
//[Authorize]
public class RepositoryController : ApiController
{
//With Few methods
}
public void Configuration(IAppBuilder app)
{
ConfigureOAuth(app);
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
}