var deferred = $q.defer();
$http.post([serviceBase, "token"].join(''), data, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).success(function (response) {
console.log("login response", response);
localStorageService.set(_keyAuthorizationData, { token: response.access_token, userName: loginData.userName });
_authentication.isAuth = true;
_authentication.userName = loginData.userName;
deferred.resolve(response);
}).error(function (err, status) {
_logOut();
deferred.reject(err);
});
return deferred.promise;
};
var _transferPersoon = function (portal, data) {
var externalAPI = "";
if (portal == "portal1") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal2") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal3") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal4") {
externalAPI = "https://urltoportal/webapi/";
} else {
externalAPI = serviceBase;
}
var tokenData = {
username: "cactustransfer",
password: "bbbbbb",
grant_type: "password"
};
var data = ["grant_type=password&username=", "transferaccount", "&password=", "password"].join('');
$http.post([externalAPI, "token"].join(''), data, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).success(function (response) {
return response.access_token;
})
}
{error: "unsupported_grant_type"}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
Cactus.Business.DataModel.GEBRUIKER gebruiker = null;
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {"*"});
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
/*
* Authenticatie methode voor het verplaatsen van personeel
* Deze kan niet uitgevoerd worden als het request IP niet in het lijstje van hosts staat.
* Dit is een extra beveiliging.
*/
if (context.UserName == "cactustransfer")
{
if (!hostVerify.IsValidHost(context.Request.RemoteIpAddress))
{
using (UnitOfWork work = new UnitOfWork())
{
gebruiker = work.GebruikerRepository.ValidateUser("transferaccount", "password");
}
}
}
if (gebruiker == null)
{
using (UnitOfWork work = new UnitOfWork())
{
gebruiker = work.GebruikerRepository.ValidateUser(context.UserName, context.Password);
if (gebruiker == null)
{
context.SetError("invalid_grant",
"The username or password is incorrect, or you have insufficient rights", context.Request.RemoteIpAddress);
return;
}
}
}
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
identity.AddClaim(new Claim("providerID", gebruiker.gebruikerId.ToString()));
//identity.AddClaim(new Claim("providerID", gebruiker.persoon.ToString()));
context.Validated(identity);
}
$http.post([serviceBase, "token"].join(''), data, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).success(function (response) {
console.log("login response", response);
localStorageService.set(_keyAuthorizationData, { token: response.access_token, userName: loginData.userName });
_authentication.isAuth = true;
_authentication.userName = loginData.userName;
deferred.resolve(response);
}).error(function (err, status) {
_logOut();
deferred.reject(err);
});
return deferred.promise;
};
var _transferPersoon = function (portal, data) {
var externalAPI = "";
if (portal == "portal1") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal2") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal3") {
externalAPI = "https://urltoportal/webapi/";
} else if (portal == "portal4") {
externalAPI = "https://urltoportal/webapi/";
} else {
externalAPI = serviceBase;
}
var tokenData = {
username: "cactustransfer",
password: "bbbbbb",
grant_type: "password"
};
var data = ["grant_type=password&username=", "transferaccount", "&password=", "password"].join('');
$http.post([externalAPI, "token"].join(''), data, { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).success(function (response) {
return response.access_token;
})
}
{error: "unsupported_grant_type"}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
Cactus.Business.DataModel.GEBRUIKER gebruiker = null;
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {"*"});
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
/*
* Authenticatie methode voor het verplaatsen van personeel
* Deze kan niet uitgevoerd worden als het request IP niet in het lijstje van hosts staat.
* Dit is een extra beveiliging.
*/
if (context.UserName == "cactustransfer")
{
if (!hostVerify.IsValidHost(context.Request.RemoteIpAddress))
{
using (UnitOfWork work = new UnitOfWork())
{
gebruiker = work.GebruikerRepository.ValidateUser("transferaccount", "password");
}
}
}
if (gebruiker == null)
{
using (UnitOfWork work = new UnitOfWork())
{
gebruiker = work.GebruikerRepository.ValidateUser(context.UserName, context.Password);
if (gebruiker == null)
{
context.SetError("invalid_grant",
"The username or password is incorrect, or you have insufficient rights", context.Request.RemoteIpAddress);
return;
}
}
}
identity.AddClaim(new Claim("sub", context.UserName));
identity.AddClaim(new Claim("role", "user"));
identity.AddClaim(new Claim("providerID", gebruiker.gebruikerId.ToString()));
//identity.AddClaim(new Claim("providerID", gebruiker.persoon.ToString()));
context.Validated(identity);
}