Xamarin.forms Get the token after logging in [closed] - xamarin

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Sorry for my poor language. I would like to know how to get the token after logging in in xamarin.forms. I enter my email and password in postman, it generates the token visible at the bottom
I authorize myself by entering Bearer + token

You can use HttpClient to Consume a RESTful Web Service and get the token from the response:
public async void test() {
var client = new HttpClient();
string jsonData = #"{""username"" : ""myusername"", ""password"" : ""mypassword""}";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("your request url", content);
// this result string should be something like: "{"token":"rgh2ghgdsfds"}"
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}

Related

"How to fix io.jsonwebtoken.ExpiredJwtException error?" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 days ago.
Improve this question
"I'm using the JWT library in a Spring-based Java application and I'm facing an error "io.jsonwebtoken.ExpiredJwtException: JWT expired at 2023-02-09T12:31:06Z. Current time: 2023-02-13T09:29:07Z, a difference of 334681633 milliseconds. Allowed clock skew: 0 milliseconds.".
I tried to generate a JWT token using the code below, but I am getting an "Expired Jwt Exception".
Here's my code:
private String generateToken(Map<String, Object> extractClaims, UserDetails userDetails) {
return Jwts.builder()
.setClaims(extractClaims)
.setSubject(userDetails.getUsername())
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(new Date(System.currentTimeMillis()+1000 *60 *30))
.signWith(getSignKey(), SignatureAlgorithm.HS256)
.compact();
}

Spring Webflux Upload Large Image File and Send The File with WebClient in Streaming Way [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am using spring webflux functional style.
I want to create a endpoint which accepts large image files and send this files to another service with webClient in streaming way.
All file processing should be in streaming way because I don't want to my app crush because of outofmemory.
Is there anyway to do this ?
Probably something like this:
#PostMapping(value = "/images/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public Mono<ResponseEntity<Void>> uploadImages(#RequestPart("files") Flux<FilePart> fileParts) {
return fileParts
.flatMap(filePart -> {
return webClient.post()
.uri("/someOtherService")
.body(BodyInserters.fromPublisher(filePart.content(), DataBuffer.class))
.exchange()
.flatMap(clientResponse -> {
//some logging
return Mono.empty();
});
})
.collectList()
.flatMap(response -> Mono.just(ResponseEntity.accepted().build()));
}
This accepts MULTIPART FORM DATA where you can attach multiple image files and upload them to another service.

Documenting custom error codes from ASP.NET Web API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Are there any best practices for documenting possible error codes returned from a Web API call? I'm referring to custom logic errors as opposed to standard HTTP return codes.
For example, consider an API method to allow a user to change their password. A possible error condition might be that the new password provided has already been used by that user previously (ie, password history requirement). You could use the following code to communicate that to the caller:
public HttpResponseMessage ChangePassword(string oldPassword, string newPassword)
{
try
{
passwordService.ChangePassword(oldPassword, newPassword)
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception ex)
{
switch(ex.Message)
{
case "PasswordHistoryFailed":
return Request.CreateResponse(HttpStatusCode.BadRequest, new CustomErrorClass("FailedHistoryRequirements"));
break;
...
}
}
}
In this example, I'm using a custom error class to wrap a custom error code of "FailedHistoryRequirements". I could have more error codes for this operation such as too many password changes in a 24 hour period or whatever.
I want to know if there's an accepted way to automatically document these custom error codes in the method's XML Code Comments so that it can be consumed by a documentation generator like Swashbuckle/Swagger or something similar.
If you use Swagger, you can use the SwaggerResponse attribute.
Check out this blog post:
https://mattfrear.com/2015/04/21/generating-swagger-example-responses-with-swashbuckle/
I do this by catching a specific exception type, rather than parsing the message.
Here I have MyDepartmentCentricBaseException as a custom exception. I may have 2-3 exceptions that derive from it. But by using a base-exception, I keep my exception catching cleaner.
try
{
/* do something */
}
catch (MyDepartmentCentricBaseException deptEx)
{
HttpResponseException hrex = this.GetDepartmentMissingHttpResponseException(deptEx.DepartmentSurrogateKey);
throw hrex;
}
catch (Exception ex)
{
/* log it somewhere !*/
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
private HttpResponseException GetDepartmentMissingHttpResponseException(int DepartmentSurrogateKey)
{
HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("No Department with DepartmentSurrogateKey = {0}", DepartmentSurrogateKey)),
ReasonPhrase = "DepartmentSurrogateKey Not Found"
};
HttpResponseException returnEx = new HttpResponseException(resp);
return returnEx;
}
There are other ideas here:
https://learn.microsoft.com/en-us/aspnet/web-api/overview/error-handling/exception-handling
But I don't know of a way of auto-voodoo-it with documentation. :(

What programing languages can be used to send emails [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am about to start writing a program that will have a GUI interface with the user that prompts for a number between 1-100. The program then emails me that number(this program would be running on an unknown users computer).
I am unable to decide what programing language to use for such a project. Can anyone suggest a language that is able to do GUI, and send emails from someone elses computer? (Preferable be able to save this program as a .exe or some single file that can be run from their computer. Also would prefer a link as to how to email in that language, but I am fine doing that research myself, just unsure what language to start researching in. If I left anything out please leave a comment asking for clarification. Thanks for any help I can get.
Use C# cus you know it's awesome (heavily biased answer) and here's the code
private bool sendMsg (string from, string to, string subject , string messageBody)
{
MailMessage message = null;
try
{
message = new MailMessage(from, to);
using (message) {
message.Subject = subject;
//message.CC.Add(CCemailAddress);
message.Body = messageBody;
message.IsBodyHtml = false;
SmtpClient client = new SmtpClient("smtp.outlook.com", 587);
client.Credentials = new System.Net.NetworkCredential(from, "Sending Accounts Password");
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true; //enable SSL
client.Send(message);
client.Dispose();
}
}
catch
{
return false;
}
message.Dispose();
return true;
}

asp.net mvc3, api twitter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Somebody can explain me this code :
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
var auth = new MvcAuthorizer
{
Credentials = new SessionStateCredentials()
{
ConsumerKey = this.client.ConsumerKey,
ConsumerSecret = this.client.ConsumerSecret,
OAuthToken = identity.Token.Token
}
};
the difference between the two codes
Thanks,
Logically, there is no difference. I'm making the assumption that "credentials" in the first example is a SessionStateCredentials that was instantiated previously in the code. The second example uses object initialization syntax to do the same thing.

Resources