How to handle cloudboost errors in Ionic2? - cloudboost

The error I get when the user fails to log in is "Error: Request failed with status code 401". This error is logged here:
static login(username : string, password : string){
return new Promise(resolve =>{
let user = new CB.CloudUser();
user.set('username', username);
user.set('password', password);
user.logIn({
success: function(user) {
console.log("user");
resolve();
},
error: function(error) {
console.log(error);
resolve(error);
}
});
});
}
But what I need is the error that actually says what went wrong e.g. "invalid username" or "User is not authenticated".
How do I get these?

Error: Request failed with status code 401
This error generally means that the login request you made to the server was not authenticated/ you were not authorized to make the login request. This can mean that the CB instance is not properly initialized. Please check the appId and the master/client key you are using to initialize the CB instance.

Related

"Manifest signature did not verify successfully"

I've been trying to figure this out for a few days now.
The .pkpass appears to build correctly however, when I drag it into Simulator the following errors are logged in Console
-CMS verification error: -26275
-Signature validation: * FAILED *
-Invalid data error reading pass pass.com.example.pass/XXXXX. Manifest signature did not verify successfully
-Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid." UserInfo={NSLocalizedDescription=The pass cannot be read because it isn’t valid., NSUnderlyingError=0x60000086e6d0 {Error Domain=PKPassKitErrorDomain Code=1 "Manifest signature did not verify successfully" UserInfo={NSLocalizedDescription=Manifest signature did not verify successfully}}}.
When I unpack the .pkpass, the signature.exe file is there but it is completely empty.
I can see that its loading the signing key file but then it never seems to get validated.
Code is as follows:
formatVersion : 1,
passTypeIdentifier: 'pass.com.example.pass',
teamIdentifier: 'XXXXXXX',
webServiceURL : "https://example.com",
authenticationToken : "1234567",
organizationName: 'Test',
description: 'example pass'
});
template.loadImagesFrom('./images');
template.fields.barcode = {
'format': 'PKBarcodeFormatPDF417',
'message': '123456789',
'messageEncoding':'iso-8859-1'
};
template.fields.serialNumber = 'E5982H-I2';
template.keys('./keys', 'password');
let pass = template.createPass({
primaryFields: [
{
key: "pass",
label: "Project",
value: "please work"
}
]
});
var file = fs.createWriteStream("Callsheet.pkpass");
pass.on("error", function(error) {
console.error(error);
process.exit(1);
})
pass.pipe(file);
app.get("/newpass", function(request, response) {
pass.render(response, function(error) {
if (error)
console.error(error);
});
});
In the keys folder I have AppleWWDRCA.cer, Certificates.p12, com.example.pass.pem and wwdr.pem
I'm not sure if this where I have gone wrong but any help would be much appreciated
Was a bug in the Passbook library. Fixed using the suggestions from https://github.com/assaf/node-passbook/pull/70

Handle failed Silent Authentication in Open Id Connect

I have an ASP.NET site that uses Open Id Connect to authenticate with Identity Server.
When the authentication token is about to expire I have added a silent authentication(prompt=none) that will renew the token without showing any login dialog to the user.
This works fine as long as the user is still logged in to Identity Server.
If the user is no longer logged in, an "login_required" error is returned. I want to handle this error by just letting it fail silently and redirect the user back to the page where the authentication started.
When being returned with an error to the AuthenticationFailed notification, the RedirectUri dosen't seem to be available though. Are there any way to access the RedirectUri after getting the error?
My configuration looks something like this(abbreviated):
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions {
...
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthenticationFailed = context =>
{
// if we failed to authenticate without prompt
if (context.ProtocolMessage.Error == "login_required")
{
context.HandleResponse();
//context.Response.Redirect("The url to the page where RedirectToIdentityProvider was triggered");
return Task.FromResult(0);
}
context.HandleResponse();
context.Response.Write(context.Exception.Message);
return Task.FromResult(0);
},
RedirectToIdentityProvider = async context =>
{
...
if (ShouldReAuthenticate())
{
context.ProtocolMessage.SetParameter("prompt", "none");
}
...
}
}
});
I managed to solve this by using the ISecureDataFormat.Unprotect() method to read the information in the state message.
It can probably could be done more elegantly, but something like this:
if (!string.IsNullOrEmpty(context.ProtocolMessage.State) ||
context.ProtocolMessage.State.StartsWith("OpenIdConnect.AuthenticationProperties="))
{
var authenticationPropertiesString = context.ProtocolMessage.State.Split('=')[1];
AuthenticationProperties authenticationProperties = context.Options.StateDataFormat.Unprotect(authenticationPropertiesString);
return authenticationProperties.RedirectUri;
}

axios async await function not returning validation errors

export const register = (user, callback, errorback) => async dispatch => {
try{
let response = await axios.post(`${PINGUIN_ROOT_URL}/users/create`, user)
if (response.data.auth_token){
auth_token = response.data.auth_token
dispatch({ type: REGISTER_SUCCESS, payload: auth_token})
callback()
} else {
let error = response
throw error
}
}catch(error){
dispatch({type: REGISTER_FAIL})
errorback()
}
Hi, I am building a login register based off of what we have learned. It works but for some reason the error validations wont come back. I built a rails api and I see the validation errors when I use postman but when I try to get the errors back using redux the register function above gets to the "let response = .." line and immediately goes to the catch(error) line. I dont know how to pass back the actual validation errors that I see when I use post man because the error that is being caught is the following:
Error: Request failed with status code 422
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:538)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:381)
at XMLHttpRequest.js:485
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:250)
at MessageQueue.js:101
Now again, the code is working when it actually logs in the user however it fails to actually give me the validation errors that I need. I see the validation errors comming back as json in postman but i do not get to see them in practice. Help please?
You can get the response object from your error object as error.response
try{
let response = await axios.post(`${PINGUIN_ROOT_URL}/users/create`, user)
...
} catch(error){
console.error(error.response)
}

Cloudboost - Register User Error

I'm using the example from your quickstart section on your website to register a user, problem is, it is throwing back an error. Did I miss something? See below for the error.
Error: Request failed with status code 400 -
https://api.cloudboost.io/user/ohoydfjlnmnf/signup
CB.CloudApp.init('ohoydfjlnmnf', '********-3*9b-4**b-9***-a**b**2**5*1');
//Registration
var user = new CB.CloudUser();
user.set('username', 'NEWUSER');
user.set('password', 'PASSWORD');
user.set('email', 'EMAILADDRESS');
user.signUp({
success: function(user) {
//Registration successfull
console.log(user);
},
error: function(error) {
//Error in user registration.
console.log(error);
}
});

Microsoft Graph API - Updating password

I am using the Microsoft Graph API sample project. I am able to login fine.
I am trying to update the password of the user that is logged in using the following code:
public async Task<bool> UpdatePassword(GraphServiceClient graphClient, string newPassword)
{
User me = await graphClient.Me.Request().UpdateAsync(new User
{
PasswordProfile = new PasswordProfile
{
Password = newPassword,
ForceChangePasswordNextSignIn = false
},
});
return true;
}
When I execute the code, I get the following error:
{
Status: 500
Message: "No offeractions were provided for validating consent."
Internal error: "empty offerActions array."
}
Any idea what I might be doing incorrectly?
I gave access to everything "Users" related via the App Registration Portal at https://apps.dev.microsoft.com
Thank you!
There is a baked-in ChangePassword() function that you'll want to use for this:
await graphClient.Me.ChangePassword("current-pwd, "new-pwd").Request().PostAsync();

Resources