GenAuth DocsDocuments
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Concepts
User Guide
Development Integration
AgentAuth
Metadata
Development Integration
Multi-tenant (beta)
Console Documentation
Multi-tenant Console
Tenant Console
Saas Application Demo
Old version
Development Integration
  • API

  • SDK

    • Java

      • Installation and use
      • User authentication module

        • Login

          • Account password login
          • Username password login
          • Mobile phone number password login
          • Email password login
          • Login by email verification code
          • Login by mobile phone verification code
          • LDAP account login
          • AD account login
          • Generate login address
          • Login with user credentials
          • Login with mobile social networking
          • Get Alipay AuthInfo
          • Generate a QR code for login
          • Query QR code status
          • Use QR code ticket to exchange for TokenSet
          • Self-built APP scan code login: APP end modifies QR code status
        • Logout

        • Manage Token

        • Register

        • User information

        • Account Binding

        • MFA Factor Management

        • User-related resources

        • Message service

        • Authentication

        • Others

        • OIDC module
        • OAuth module
        • SAML module
        • CAS module
        • Events
      • Management module

    • Node.js

    • Python

  • Error Codes
  1. Development Integration
  2. /
  3. SDK
  4. /
  5. Java
  6. /
  7. User authentication module

  8. /
  9. Login

  10. /
  11. Login with user credentials

¶ Login using user credentials

Update time: 2025-07-23 07:34:21
Edit

This document is automatically generated based on https://github.com/authing/authing-docs-factory based on the https://api-explorer.genauth.ai V3 API, and is consistent with the API parameters and return results. If this document description is incorrect, please refer to the V3 API.

This endpoint is a login endpoint based on direct API calls, which is suitable for scenarios where you need to build your own login page. ** This endpoint does not currently support MFA, information completion, first password reset and other processes. If necessary, please use the OIDC standard protocol authentication endpoint. **

Note: Depending on the ** application type ** you selected when creating the application in GenAuth and the ** token exchange authentication method ** configured in the application, different forms of verification of the client's identity are required when calling this interface.

Click to expand details

You can find the Exchange token authentication method configuration item in Application - Self-built application - Application details - Application configuration - Other settings - Authorization configuration in the GenAuth console (opens new window):

Single-page web applications and client applications are hidden, and the default value is none, which is not allowed to be modified; backend applications and standard web applications can modify this configuration item.

¶ When the exchange token authentication method is none

No additional operations are required to call this interface.

¶ When the exchange token authentication method is client_secret_post

When calling this interface, the client_id and client_secret parameters must be passed in the body as conditions for verifying the client identity. Among them, client_id is the application ID, and client_secret is the application secret key.

¶ When exchanging token authentication mode is client_secret_basic

When calling this interface, the authorization request header must be carried in the HTTP request header as a condition for verifying the client's identity. The format of the authorization request header is as follows (where client_id is the application ID, and client_secret is the application secret key.):

Basic base64(<client_id>:<client_secret>)

Result Example:

Basic NjA2M2ZiMmYzY3h4eHg2ZGY1NWYzOWViOjJmZTdjODdhODFmODY3eHh4eDAzMjRkZjEyZGFlZGM3

JS code example:

"Basic " + Buffer.from(client_id + ":" + client_secret).toString("base64");

¶ Method Name

AuthenticationClient.signInByCredentials

¶ Request Parameters

NameType
Is it required
Default value
Description
Example Value
connectionstringyes-Authentication method:
- PASSWORD: Use password for authentication.
- PASSCODE: Use one-time temporary verification code for authentication.
- LDAP: Authentication based on LDAP user directory.
- AD: Authentication based on Windows AD user directory.
PASSWORD
passwordPayloadSignInByPasswordPayloadDtono-This parameter is required when the authentication method is PASSWORD.{"email":"test@example.com","password":"passw0rd"}
passCodePayloadSignInByPassCodePayloadDtoNo-This parameter is required when the authentication method is PASSCODE{"email":"test@example.com","passCode":"passw0rd"}
adPayloadSignInByAdPayloadDtoNo-This parameter is required when the authentication method is AD{"sAMAccountName":"test","password":"passw0rd"}
ldapPayloadSignInByLdapPayloadDtoNo-This parameter is required when the authentication method is LDAP{"sAMAccountName":"test","password":"passw0rd"}
optionsSignInOptionsDtoNo-Optional parameters{"passwordEncryptType":"none"}
client_idstringNo-Application ID. Required when the application's "Exchange token authentication method" is configured as client_secret_post.6342b8537axxxx047d314109
client_secretstringNo-Application secret key. Required when the application's "Exchange token authentication method" is configured as client_secret_post.4203d30e5e915xxxxxx26c31c9adce68

¶ Sample Code

package test.authentication;

import cn.authing.sdk.java.client.AuthenticationClient;
import cn.authing.sdk.java.dto.LoginTokenRespDto;
import cn.authing.sdk.java.dto.SignInByPasswordPayloadDto;
import cn.authing.sdk.java.dto.SigninByCredentialsDto;
import cn.authing.sdk.java.enums.AuthMethodEnum;
import cn.authing.sdk.java.model.AuthenticationClientOptions;
import cn.authing.sdk.java.util.JsonUtils;

public class SignInByCredentialsTest {
    // Need to be replaced with your GenAuth App ID
    private static final String APP_ID = "AUTHING_APP_ID";
    // Need to be replaced with your GenAuth App Secret
    private static final String APP_SECRET = "AUTHING_APP_SECRET";
    // Need to be replaced with your GenAuth App Host
    private static final String APP_HOST = "AUTHING_APP_HOST";

    public static void main(String[] args) throws Throwable {
        AuthenticationClientOptions clientOptions = new AuthenticationClientOptions();
        clientOptions.setTokenEndPointAuthMethod(AuthMethodEnum.CLIENT_SECRET_BASIC.getValue());
        clientOptions.setAppId(APP_ID);
        clientOptions.setAppSecret(APP_SECRET);
        clientOptions.setAppHost(APP_HOST);

        AuthenticationClient client = new AuthenticationClient(clientOptions);

        SigninByCredentialsDto reqDto = new SigninByCredentialsDto();
        reqDto.setConnection(SigninByCredentialsDto.Connection.PASSWORD);
        SignInByPasswordPayloadDto passwordPayloadDto = new SignInByPasswordPayloadDto();
        passwordPayloadDto.setPassword("123");
        passwordPayloadDto.setAccount("test");
        passwordPayloadDto.setEmail("123@qq.com");
        reqDto.setPasswordPayload(passwordPayloadDto);
        LoginTokenRespDto response = client.signInByCredentials(reqDto);
        System.out.println(JsonUtils.serialize(response));
    }
}

¶ Request Response

Type: LoginTokenRespDto

NameTypeDescription
statusCodenumberBusiness status code, which can be used to determine whether the operation is successful. 200 means success.
messagestringDescription
apiCodenumberSegmented error code, which can be used to get the specific error type (successful request does not return). For a detailed list of error codes, please see: API Code List (opens new window)
requestIdstringRequest ID. Returned when the request fails.
dataLoginTokenResponseDataDtoResponse data

Example Results:

{
  "statusCode": 200,
  "message": "Operation successful",
  "requestId": "934108e5-9fbf-4d24-8da1-c330328abd6c",
  "data": {
    "scope": "openid profile",
    "access_token": "eyJhbGciOiJSxxxxx",
    "id_token": "eyJhbGxxxx",
    "refresh_token": "WPsGJbvpBjqXz6IJIr1UHKyrdVF",
    "token_type": "bearer",
    "expire_in": 7200
  }
}

¶ Data Structure

¶ SignInByPasswordPayloadDto

NameType
Is it required
Description
Example Value
passwordstringyesUser password, unencrypted by default. All GenAuth APIs transmit passwords securely via HTTPS, which ensures security to a certain extent.
If you need a higher level of security, we also support RSA256 and the national secret SM2 password encryption methods. For details, see the optional parameter options.passwordEncryptType.
passw0rd
accountstringnoUser account (username/mobile number/email)test
emailstringnoEmail, case-insensitive.test@example.com
usernamestringNoUsernametest
phonestringNoPhone number188xxxx8888

¶ SignInByPassCodePayloadDto

NameType
Is it required
Description
Example Value
passCodestringYesOne-time temporary verification code. You need to call the send SMS or send email interface to obtain the verification code first.123456
emailstringNoEmail address, case insensitive.114114
phonestringNoMobile phone number188xxxx8888
phoneCountryCodestringNoMobile phone area code. This field is optional for mobile phone numbers in mainland China. The GenAuth SMS service does not yet support international mobile phone numbers. You need to configure the corresponding international SMS service in the GenAuth console. For a complete list of mobile phone area codes, please refer to https://en.wikipedia.org/wiki/List_of_country_calling_codes.+86

¶ SignInByAdPayloadDto

NameType
Is it required
Description
Example Value
passwordstringYesUser password, unencrypted by default. All GenAuth APIs transmit passwords securely via HTTPS, which can ensure security to a certain extent.
If you need a higher level of security, we also support RSA256 and national secret SM2 password encryption methods. See the optional parameter options.passwordEncryptType for details.
passw0rd
sAMAccountNamestringisthe sAMAccountName of the account in the Windows AD user directorytest

¶ SignInByLdapPayloadDto

NameType
Is it required
Description
Example Value
passwordstringyesUser password, unencrypted by default. All GenAuth APIs transmit passwords securely via HTTPS, which can ensure security to a certain extent.
If you need a higher level of security, we also support RSA256 and national secret SM2 password encryption methods. For details, see the optional parameter options.passwordEncryptType.
passw0rd
sAMAccountNamestringyessAMAccountName of the account in the LDAP AD user directory114114

¶ SignInOptionsDto

NameType
Is it required
Description
Example Value
scopestringnoThe permissions that need to be requested, must include openid. If you need to obtain the mobile phone number and email, you need to include phone email; if you need refresh_token, you need to include offline_access. Please separate multiple scopes with spaces. The decoded content of id_token will contain the user information related fields corresponding to these scopes.
- openid: Must be included.
- profile: Returns birthdate, family_name, gender, given_name, locale, middle_name, name, nickname, picture, preferred_username, profile, updated_at, website, zoneinfo fields.
- username: Returns username.
- email: Returns email, email_verified.
- phone: Returns phone_number, phone_number_verified.
- offline_access: If this parameter exists, the token interface will return the refresh_token field.
- roles: Returns the user's role list.
- external_id: The user ID of the original system.
- extended_fields: Returns the user's extended field information, the content is an object, the key is the extended field name, and the value is the extended field value.
- tenant_id: Returns the user's tenant ID.
openid profile
clientIpstringNoThe real IP address of the client. By default, GenAuth will identify the IP address of the request source as the IP address of the user's login. If you call this interface in the backend server, you need to set this IP to the user's real request IP.192.168.0.1
contextobjectNoAdditional request context that will be passed to the context object of the Pipeline (opens new window) before and after authentication. Learn how to get the additional context passed in the context parameter of Pipeline (opens new window).{"source":"utm"}
tenantIdstringNoTenant ID625783d629f2bd1f5ddddd98c
customDataobjectNoTo set additional user custom data, you need to configure custom data (opens new window) in the GenAuth console first.{"school":"pku","age":"20"}
autoRegisterbooleanNoWhether to enable automatic registration. If set to true, an account will be automatically created for the user if it does not exist. Note: This parameter is only valid for the specified username and password, email password, and mobile phone number password. This parameter cannot be set for general account passwords.
captchaCodestringNoCaptcha graphic verification code, case-insensitive. When the security policy is set to verification code and the limit of failed logins is triggered, you will need to fill in a graphic verification code the next time you log in.a8nz
passwordEncryptTypestringNoPassword encryption type, supports encryption using RSA256 and the national secret SM2 algorithm. The default is none, no encryption.
- none: Do not encrypt the password, use plain text for transmission.
- rsa: Use the RSA256 algorithm to encrypt the password. You need to use the RSA public key of the GenAuth service for encryption. Please read the introduction section to learn how to obtain the RSA256 public key of the GenAuth service.
- sm2: Use the national secret SM2 algorithm (opens new window) to encrypt the password. You need to use the SM2 public key of the GenAuth service for encryption. Please read the introduction section to learn how to obtain the SM2 public key of the GenAuth service.
sm2

¶ LoginTokenResponseDataDto

NameType
Is it required
Description
Example Value
scopestringnoScope corresponding to access_tokenopenid profile
access_tokenstringnoAPI call credentials, authorized to access resource API within a limited timeeyJhbGciOiJSxxxxx
id_tokenstringnoUser's identity credentials, which will contain user information after parsingeyJhbGxxxx
refresh_tokenstringnorefresh_token is used to obtain a new AccessTokenWPsGJbvpBjqXz6IJIr1UHKyrdVF
token_typestringyesToken typebearer
expire_innumberyesExpiration time in seconds7200
Previous article: Generate login address Next article: Login with mobile social networking
  • Method Name
  • Request Parameters
  • Sample Code
  • Request Response
  • Data Structure

User identity management

Integrated third-party login
Customized authentication process

Enterprise internal management

Single sign-on
Multi-factor authentication
Permission management

Developer

Development Documentation
GitHub (opens new window)

Company

official@genauth.ai
16th Floor, Building B, Beichen Century Center, Chaoyang District, Beijing (Total)
Room 406, 4th Floor, Block B, No. 200, Tianfu Fifth Street, High-tech Zone, Chengdu (Branch)

© Beijing Steamory Technology Co., Ltd.