Small example using Xamarin Forms 2.5, MVC5 and web api.
Login in Xamarin Forms 2.5 with our API. Get, create, delete and update (CRUD) records from Xamarin Forms from our API. All queries from Xamarin Forms are made with token.
The Hospital app is available for two platforms:
- iOS
- Android
There are 5 different solutions:
Api: Project with ASP.NET Web API 2.
BD: Project where we define our classes through code, and EF is responsible for generating the database and everything necessary to fit the classes in them.
Backoffice: Web with a Cpanel for the administration of the app.
HospitalApp: Main project developed with Xamarin.Forms.
Model The common models of all the projects.
Download or clone the repository. This is a solution with five projects.
Rebuild the solution to get all neccesary NuGet packages.
Configure a connection string for SQL Server in the Web.config
<connectionStrings>
<add name="DefaultConnection" connectionString="Data
Source=YOURTDATABASE;
Initial Catalog=YOURNAMEDB; Persist Security
Info=True;User ID=YOURUSER;Password=YOURPASSWORD”"
providerName="System.Data.SqlClient" />
</connectionStrings>-->
By default, if you don't customise anything, Identity configures a default set of validation rules for new passwords. If you want to change these values, you can change the file called App_Start/IdentityConfig.cs
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6, // Passwords must be at least 6 characters
RequireNonLetterOrDigit = false, // Passwords must have at least one digit ('0'-'9')
RequireDigit = false, // Passwords must have at least one non alphanumeric character
RequireLowercase = false, // // Passwords must have at least one lowercase ('a'-'z')
RequireUppercase = false, // Passwords must have at least one uppercase ('A'-'Z')
};
In our PCL, the file App.xaml you can change the color
<Color x:Key="MainColor">#273646</Color>
<Color x:Key="FontColor">#2d8dd6</Color>
<Color x:Key="AccentColor1">#2371aa</Color>
<Color x:Key="AccentColor2">#e44235</Color>
<Color x:Key="BackgroundColor">#e9eeef</Color>
In our PCL, the file Services/HttpService.cs you must put the url of your api and prefix
private const string UrlApi = "YOURAPI";
private const string tokenType = "bearer";
protected const string FirstVersion = "/api";
- Rest api tutorial - Microsoft
- Rest api tutorial - hackernoon
- Rest api tutorial - code-maze
- Rest api tutorial - solidgeargroup
Enjoy!
OAuth 2.0 protocol and Microsoft Owin Library will help us. Owin is basically creating own pipeline between iis and application to manage requests.
In the file Startup.Auth.cs an OWIN Authorization server is configured to accept login (token) HTTP requests at /Token endpoint and external login requests at /api/Account/ExternalLogin
- Visual Studio 2017 version 15.3 or Visual Studio for Mac version 7.3
- Windows 10
- Microsoft Azure subscription
The following tools are essential:
- Genymotion - The Best Android Emulator
- Postman - Application which is used to fire requests to an API. It is possible to make different kinds of HTTP requests – GET, POST, PUT, PATCH and DELETE.
- Quicktype - Generate c# classes from json.
- Color Adobe - To create color schemes for my designs. For this project I have choosen
This project uses some third-party assets with a license that requires attribution:
- Settings : by James Montemagno
- MvvmLightLibsStd10 : by lbugnion
- Connectivity : by James Montemagno
- Newtonsoft : by jamesnk
- ImageCirclePlugin: by James Montemagno
- EntityFramework: by Microsoft's
Getting Started with ASP.NET MVC 5
The MIT License (MIT) see License file