ASP. zero--Token-based authentication &swagger UI

Source: Internet
Author: User
Tags two factor

Token-based authentication

any application can authenticate and use any feature in the application as an API. For example, you can create a mobile application that consumes the same API. In this section, we will demonstrate the use of the API (Google Chrome extensions) from Postman.

Certifications

We recommend that you disable two-factor authentication for users who are using Remote authentication. Otherwise, the client should implement two factor authentication processes. We assume that you have an administrator user for the default tenant Two-factor authentication is disabled because we will use it in this example.

The following headers should be configured for all requests (Abp.tenantid is the ID of the default tenant), which is not required for a single tenant application, or if you want to work with host users):

then we can send the user name and password as POST request to/HTTP/localhost:62114 /api/tokenauth/authenticate

in the returned response, the Accesstoken will be used for the authorization API.

using the API

after validating and obtaining an access token, we can use it to invoke any authorized operation. all Services can be used remotely. For example, we can use User Services to get a list of users :

we sent a GET request to HTTP. localhost:62114/api/services/app/user/getusers and added the title as " Bearer <accessToken> ". returns the JSON containing list of users.

SWAGGER UI

The SWAGGER UI is integrated into ASP. NET zero, but is disabled by default . The Swagger UI configuration is located in the S Tartup class in the. Web Project . You can enable it by uncomment the related line:

in the Start Configureservices method, enable the following line:

Services. Addswaggergen ();

And in the Startup.configure method, enable the following line:

app. Useswagger (); app. Useswaggerui ();

You can Use this URL Browse Swagger UI: "/ swagger/ui ".

As a result, anyone (or any application) can easily explore, test, and use the API??。

ASP. zero--Token-based authentication &swagger UI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.