Logto is an Auth0 alternative designed for modern apps and SaaS products. It offers both Cloud and Open-source services to help you quickly launch your identity and management (IAM) system. Enjoy authentication, authorization, and multi-tenant management all in one.
We recommend starting with a free development tenant on Logto Cloud. This allows you to explore all the features easily.
In this article, we will go through the steps to quickly build the Alipay (Native) sign-in experience (user authentication) with .NET Core (MVC) and Logto.
Prerequisites
- A running Logto instance. Check out the introduction page to get started.
- Basic knowledge of .NET Core (MVC).
- A usable Alipay (Native) account.
Create an application in Logtoâ
Logto is based on OpenID Connect (OIDC) authentication and OAuth 2.0 authorization. It supports federated identity management across multiple applications, commonly called Single Sign-On (SSO).
To create your Traditional web application, simply follow these steps:
- Open the Logto Console. In the "Get started" section, click the "View all" link to open the application frameworks list. Alternatively, you can navigate to Logto Console > Applications, and click the "Create application" button.
- In the opening modal, click the "Traditional web" section or filter all the available "Traditional web" frameworks using the quick filter checkboxes on the left. Click the ".NET Core (MVC)" framework card to start creating your application.
- Enter the application name, e.g., "Bookstore," and click "Create application".
đ Ta-da! You just created your first application in Logto. You'll see a congrats page which includes a detailed integration guide. Follow the guide to see what the experience will be in your application.
Integrate .NET Core (MVC) with Logtoâ
- The following demonstration is built on .NET Core 8.0. The SDK is compatible with .NET 6.0 or higher.
- The .NET Core sample projects are available in the GitHub repository.
Installationâ
Add the NuGet package to your project:
dotnet add package Logto.AspNetCore.Authentication
Add Logto authenticationâ
Open Startup.cs
(or Program.cs
) and add the following code to register Logto authentication services:
using Logto.AspNetCore.Authentication;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLogtoAuthentication(options =>
{
options.Endpoint = builder.Configuration["Logto:Endpoint"]!;
options.AppId = builder.Configuration["Logto:AppId"]!;
options.AppSecret = builder.Configuration["Logto:AppSecret"];
});
The AddLogtoAuthentication
method will do the following things:
- Set the default authentication scheme to
LogtoDefaults.CookieScheme
. - Set the default challenge scheme to
LogtoDefaults.AuthenticationScheme
. - Set the default sign-out scheme to
LogtoDefaults.AuthenticationScheme
. - Add cookie and OpenID Connect authentication handlers to the authentication scheme.
Sign-in and sign-out flowsâ
Before we proceed, there are two confusing terms in the .NET Core authentication middleware that we need to clarify:
- CallbackPath: The URI that Logto will redirect the user back to after the user has signed in (the "redirect URI" in Logto)
- RedirectUri: The URI that will be redirected to after necessary actions have been taken in the Logto authentication middleware.
The sign-in process can be illustrated as follows:
Similarly, .NET Core also has SignedOutCallbackPath and RedirectUri for the sign-out flow.
For the sake of clarity, we'll refer them as follows:
Term we use | .NET Core term |
---|---|
Logto redirect URI | CallbackPath |
Logto post sign-out redirect URI | SignedOutCallbackPath |
Application redirect URI | RedirectUri |
Regarding redirect-based sign-inâ
- This authentication process follows the OpenID Connect (OIDC) protocol, and Logto enforces strict security measures to protect user sign-in.
- If you have multiple apps, you can use the same identity provider (Logto). Once the user signs in to one app, Logto will automatically complete the sign-in process when the user accesses another app.
To learn more about the rationale and benefits of redirect-based sign-in, see Logto sign-in experience explained.
Configure redirect URIsâ
In the following code snippets, we assume your app is running on http://localhost:3000/
.
First, let's configure the Logto redirect URI. Add the following URI to the "Redirect URIs" list in the Logto application details page:
http://localhost:3000/Callback
To configure the Logto post sign-out redirect URI, add the following URI to the "Post sign-out redirect URIs" list in the Logto application details page:
http://localhost:3000/SignedOutCallback
Change the default pathsâ
The Logto redirect URI has a default path of /Callback
, and the Logto post sign-out redirect URI has a default path of /SignedOutCallback
.
You can leave them as are if there's no special requirement. If you want to change it, you can set the CallbackPath
and SignedOutCallbackPath
property for LogtoOptions
:
builder.Services.AddLogtoAuthentication(options =>
{
// Other configurations...
options.CallbackPath = "/Foo";
options.SignedOutCallbackPath = "/Bar";
});
Remember to update the value in the Logto application details page accordingly.
Implement sign-in/sign-out buttonsâ
First, add actions methods to your Controller
, for example:
public class HomeController : Controller
{
public IActionResult SignIn()
{
// This will redirect the user to the Logto sign-in page.
return Challenge(new AuthenticationProperties { RedirectUri = "/" });
}
// Use the `new` keyword to avoid conflict with the `ControllerBase.SignOut` method
new public IActionResult SignOut()
{
// This will clear the authentication cookie and redirect the user to the Logto sign-out page
// to clear the Logto session as well.
return SignOut(new AuthenticationProperties { RedirectUri = "/" });
}
}
Then, add the links to your View:
<p>Is authenticated: @User.Identity?.IsAuthenticated</p>
@if (User.Identity?.IsAuthenticated == true) {
<a asp-controller="Home" asp-action="SignOut">Sign out</a>
} else {
<a asp-controller="Home" asp-action="SignIn">Sign in</a>
}
It will show the "Sign in" link if the user is not authenticated, and show the "Sign out" link if the user is authenticated.
Checkpoint: Test your applicationâ
Now, you can test your application:
- Run your application, you will see the sign-in button.
- Click the sign-in button, the SDK will init the sign-in process and redirect you to the Logto sign-in page.
- After you signed in, you will be redirected back to your application and see the sign-out button.
- Click the sign-out button to clear token storage and sign out.
Add Alipay (Native) connectorâ
To enable quick sign-in and improve user conversion, connect with .NET Core (MVC) as an identity provider. The Logto social connector helps you establish this connection in minutes by allowing several parameter inputs.
To add a social connector, simply follow these steps:
- Navigate to Console > Connectors > Social Connectors.
- Click "Add social connector" and select "Alipay (Native)".
- Follow the README guide and complete required fields and customize settings.

If you are following the in-place Connector guide, you can skip the next section.
Set up Alipay mobile appâ
Register Alipay developer accountâ
Register an Alipay developer account if you don't have one.
Create and configure Alipay appâ
- Sign in to the Alipay console with the account you have just registered.
- Go to "Web & Mobile Apps" (įŊéĄĩ&į§ģå¨åēį¨) tab in "My Application" (æįåēį¨) panel.
- Click "Create an App" (įĢåŗååģē) button to start configuring your application.
- Name your application in "Application Name" (åēį¨åį§°) following the naming conventions and upload your "Application Icon" (åēį¨åžæ ), make sure you choose "mobile application" (į§ģå¨åēį¨) as "App type" (åēį¨įąģå). For building iOS App, a unique "Bundle ID" is required. Also, "application signature" (åēį¨įžå) and "application package name" (åēį¨å å) are required for Android apps.
- After finishing creating the application, we come to the Overview page, where we should click "add ability" (æˇģå čŊå) to add "Third-party application authorization" (įŦŦ䏿šåē፿æ), "Get member information" (čˇåäŧåäŋĄæ¯) and "App Alipay login" (App æ¯äģåŽįģåŊ) before enabling Alipay sign-in.
- Go to Alipay Customer Center, and sign in with the Alipay developer account. Click "Account Center" (č´Ļåˇä¸åŋ) on the topbar and go to "APPID binding" (APPID įģåŽ), whose entrance can be found at the bottom of the sidebar. "Add binding" (æˇģå įģåŽ) by type in the APPID of the mobile application you just created in step 4.
- Click on "Sign" button of "App Alipay login", and finish signing process following the guide. After finishing this step, you are expected to find abilities you have just added in step 5 kicks in.
- Come back to Alipay open platform console page, and you can find "Interface signing method" (æĨåŖå įžæšåŧīŧå¯éĨ/č¯äšĻīŧ) in "development information" (åŧåäŋĄæ¯) section. Click "set up" (莞įŊŽ) button, and you can find yourself on a page setting signing method. "Public Key" (å ŦéĨ) is the preferred signing mode, and fill in contents from the public key file you have generated in the text input box.
- Set up "Authorization Redirect URI" (ææåč°å°å) by clicking "set up" (莞įŊŽ) button on the bottom of the Alipay console page.
${your_logto_origin}/callback/${connector_id}
is the default redirect URI used in Logto core. Theconnector_id
can be found on the top bar of the Logto Admin Console connector details page. - After finishing all these steps, go back to the top right corner of Alipay console page, and click "Submit for review" (æäē¤åŽĄæ ¸). Once the review is approved, you are good to go with a smooth Alipay sign-in flow.
You can use openssl to generate key pairs on your local machine by executing following code snippet in terminal.
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
When filling in the public key on the Alipay app setup website, you need to remove the header and footer of public.pem
, delete all newline characters, and paste the rest of the contents into the text input box for "public key".
Set up the Logto Alipay Native connector settingsâ
- In the Alipay console workspace go to "My application" (æįåēį¨) panel and click "Web & Mobile Apps" (įŊéĄĩ&į§ģå¨åēį¨) tab, you can find APPID of all applications.
- In step 7 of the previous part, you have already generated a key pair including a private key and a public key.
- Fill out the Logto connector settings:
- Fill out the
appId
field with APPID you've got from step 1. - Fill out the
privateKey
field with contents from the private key file mentioned in step 2. Please MAKE SURE to use '\n' to replace all newline characters. You don't need to remove header and footer in private key file. - Fill out the
signType
filed with 'RSA2' due to thePublic key
signing mode we chose in step 7 of "Create And Configure Alipay Apps".
- Fill out the
Config typesâ
Name | Type | Enum values |
---|---|---|
appId | string | N/A |
privateKey | string | N/A |
signType | enum string | 'RSA' | 'RSA2' |
Enable Alipay native sign-in in your appâ
iOSâ
We assume you have integrated Logto iOS SDK in your app. In this case, things are pretty simple, and you don't even need to read the Alipay SDK doc:
1. Add LogtoSocialPluginAlipay
to your Xcode project
Add the framework:

The plugin includes Alipay "minimalist SDK" (æįŽį SDK). You can directly use import AFServiceSDK
once imported the plugin.
2. Add the plugin to your LogtoClient
init options
let logtoClient = LogtoClient(
useConfig: config,
socialPlugins: [LogtoSocialPluginAlipay(callbackScheme: "your-scheme")]
)
Where callbackScheme
is one of the custom URL Schemes that can navigate to your app.
Androidâ
We assume you have integrated Logto Android SDK in your app. In this case, things are pretty simple, and you don't even need to read the Alipay SDK doc:
1. Download the Alipay "minimalist SDK" and add it to your project
Download the Alipay "minimalist SDK" (æįŽį SDK) from Logto 3rd-party Social SDKs to your project's app/libs
folder:
project-path/app/libs/alipaySdk-15.7.9-20200727142846.aar
2. Add the Alipay "minimalist SDK" as a dependency
Open your build.gradle
file:
project-path/app/build.gradle
Add the dependency:
dependencies {
// ...
implementation(files("./libs/alipaySdk-15.7.9-20200727142846.aar")) // kotlin-script
// or
implementation files('./libs/alipaySdk-15.7.9-20200727142846.aar') // groovy-script
}
Save your configurationâ
Double check you have filled out necessary values in the Logto connector configuration area. Click "Save and Done" (or "Save changes") and the Alipay (Native) connector should be available now.
Enable Alipay (Native) connector in Sign-in Experienceâ
Once you create a social connector successfully, you can enable it as a "Continue with Alipay (Native)" button in Sign-in Experience.
- Navigate to Console > Sign-in experience > Sign-up and sign-in.
- (Optional) Choose "Not applicable" for sign-up identifier if you need social login only.
- Add configured Alipay (Native) connector to the "Social sign-in" section.

Testing and Validationâ
Return to your .NET Core (MVC) app. You should now be able to sign in with Alipay (Native). Enjoy!
Further readingsâ
End-user flows: Logto provides a out-of-the-box authentication flows including MFA and enterprise SSO, along with powerful APIs for flexible implementation of account settings, security verification, and multi-tenant experience.
Authorization: Authorization defines the actions a user can do or resources they can access after being authenticated. Explore how to protect your API for native and single-page applications and implement Role-based Access Control (RBAC).
Organizations: Particularly effective in multi-tenant SaaS and B2B apps, the organization feature enable tenant creation, member management, organization-level RBAC, and just-in-time-provisioning.
Customer IAM series Our serial blog posts about Customer (or Consumer) Identity and Access Management, from 101 to advanced topics and beyond.