GitHub Login
GitHub Login (GitHubType) is an authentication element built on the GitHub platform that supports OAuth authorization for both PC and mobile environments. It manages the complete GitHub OAuth flow, user authentication, and account binding processes, making it ideal for developer communities, technical products, open-source project management, and other scenarios requiring unified identity management.
GitHub login elements follow a hierarchical structure: Meta (auths.loginTypes.Meta) → Type (auths.loginTypes.GitHubType) → Instance. Developers can rapidly create GitHub login instances using JitAI's visual development tools.
Supported authentication methods:
- PC OAuth authorization login - Redirects users to GitHub's authorization page
- Mobile OAuth authorization login - Integrates GitHub OAuth services for mobile applications
- GitHub Enterprise integration - Supports GitHub Enterprise Server authentication
Developers can also create custom Type elements or extend the official auths.loginTypes.GitHubType element within their applications to implement custom authentication workflows.
Quick Start
Creating instance elements
Directory structure
your_app/
└── auths/
└── loginTypes/
└── testGitHubLogin/ # Custom instance name
├── e.json # Element definition file
└── testGitHubLogin.json # GitHub application configuration file
e.json file
{
"title": "GitHub Login",
"type": "auths.loginTypes.GitHubType"
}
Business configuration file
{
"authConfig": {
"clientId": "Ov23xxxxxxxxxxxxxxxx",
"clientSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
}
Usage example
# Retrieve authentication element instance
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
# Get login configuration (used for frontend OAuth URL generation)
login_config = auth_element.getLoginConfig()
print(login_config) # {"clientId": "your_client_id"}
# Get GitHub client instance
client = auth_element.getClient()
# Perform OAuth login through authentication element
result = auth_element.getLoginCode(code="authorization_code_from_github")
Element Configuration
e.json configuration
| Configuration | Type | Required | Description |
|---|---|---|---|
| title | string | Yes | Element display name |
| type | string | Yes | Fixed value: auths.loginTypes.GitHubType |
Business configuration file setup
The configuration file follows the naming pattern {instance_name}.json and contains GitHub application authentication credentials:
| Configuration | Type | Required | Description |
|---|---|---|---|
| authConfig.clientId | string | Yes | GitHub OAuth App client ID |
| authConfig.clientSecret | string | Yes | GitHub OAuth App client secret |
How to obtain configuration credentials:
- Sign in to GitHub (https://github.com/)
- Navigate to "Settings" → "Developer settings" → "OAuth Apps"
- Create a new OAuth App or select an existing application
- Retrieve the Client ID and Client Secret from the application details page
- Configure the Authorization callback URL for your application
Methods
getLoginConfig
Retrieves login configuration data, primarily used for generating OAuth authorization URLs in frontend applications.
Return value
| Type | Corresponding Native Type | Description |
|---|---|---|
| JitDict | dict | Dictionary containing clientId and other configurations |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
config = auth_element.getLoginConfig()
# Returns: {"clientId": "Ov23xxxxxxxxxxxxxxxx"}
getClient
Returns a GitHub API client instance for making calls to GitHub-related endpoints.
Return value
| Type | Corresponding Native Type | Description |
|---|---|---|
| GitHubClient | object | GitHub client object |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
client = auth_element.getClient()
# Use this client to make GitHub API calls
getLoginCode
Processes GitHub OAuth authorization codes to generate login codes. This is the core authentication method for the element.
Parameter details
| Parameter | Type | Corresponding Native Type | Required | Description |
|---|---|---|---|---|
| code | Stext | str | Yes | GitHub OAuth2 authorization code |
Return value
| Type | Corresponding Native Type | Description |
|---|---|---|
| JitDict | dict | Contains loginCode and corpList for authentication results |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
result = auth_element.getLoginCode(code="auth_code_from_github")
# Returns: {"loginCode": "...", "corpList": [...]}
getUserInfoByCode
Retrieves GitHub user information using an OAuth authorization code.
Parameter details
| Parameter | Type | Corresponding Native Type | Required | Description |
|---|---|---|---|---|
| code | Stext | str | Yes | GitHub OAuth2 authorization code |
Return value
| Type | Corresponding Native Type | Description |
|---|---|---|
| JitDict | dict | GitHub user information dictionary |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
user_info = auth_element.getUserInfoByCode(code="auth_code_from_github")
# Returns GitHub user data including email, name, avatar_url, etc.
bind
Binds a GitHub user account to an existing user account.
Parameter details
| Parameter | Type | Corresponding Native Type | Required | Description |
|---|---|---|---|---|
| userId | Stext | str | Yes | User ID |
| userInfo | JitDict | dict | Yes | GitHub user information |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
user_info = auth_element.getUserInfoByCode(code="auth_code")
auth_element.bind(userId="user_id", userInfo=user_info)
unbind
Unbinds a GitHub user account.
Parameter details
| Parameter | Type | Corresponding Native Type | Required | Description |
|---|---|---|---|---|
| userId | Stext | str | Yes | User ID |
Usage example
auth_element = app.getElement("auths.loginTypes.testGitHubLogin")
auth_element.unbind(userId="user_id")
Properties
authConfig
Contains GitHub application configuration data, including clientId, clientSecret, and other authentication parameters.
| Property | Type | Description |
|---|---|---|
| clientId | str | GitHub OAuth App client ID |
| clientSecret | str | GitHub OAuth App client secret |
authType
Authentication type identifier with a fixed value representing the GitHub login type enumeration.
authModelElemName
References the associated authentication data model element name, which points to GitHubAuthModel.
Advanced Features
Data model extension
GitHubAuthModel stores GitHub user authentication data using a simplified field structure:
class GitHubAuthModel(NormalModel):
id = datatypes.AutoInt(name="id", title="Primary Key ID", primaryKey=True)
userId = datatypes.Stext(name="userId", title="UserID")
email = datatypes.Stext(name="email", title="GitHub email")
userInfo = datatypes.JitDict(name="userInfo", title="User information dictionary")
createTime = datatypes.Datetime(name="createTime", title="Creation Time")
updateTime = datatypes.Datetime(name="updateTime", title="Update Time")
Field descriptions:
userInfofield stores complete GitHub user information as a dictionary, including:id: GitHub user IDlogin: GitHub usernamename: Display nameavatar_url: Avatar URLcompany: Companylocation: Locationbio: Biography- Additional fields returned by the GitHub API
Frontend integration
Frontend applications must implement the OAuth authorization flow:
// PC OAuth login
const loginWithGitHub = async () => {
const config = await getLoginConfig(); // Retrieve configuration
const authUrl = `https://github.com/login/oauth/authorize?` +
`client_id=${config.clientId}&` +
`redirect_uri=${encodeURIComponent(redirectUri)}&` +
`scope=user:email&` +
`state=${generateState()}`;
// Redirect to GitHub authorization page
window.location.href = authUrl;
};
// Handle OAuth callback
const handleOAuthCallback = async (code: string, state: string) => {
try {
// Step 1: Get login code through authentication element
const authElement = app.getElement("auths.loginTypes.testGitHubLogin");
const loginResult = await authElement.getLoginCode(code);
// Step 2: Complete final login using AuthSvc
const authSvc = app.getElement("auths.loginTypes.services.AuthSvc");
const finalResult = await authSvc.loginByCode(
loginResult.loginCode,
"target_corp_name",
"web"
);
if (finalResult.success) {
// Login successful, redirect to main page
window.location.href = '/dashboard';
}
} catch (error) {
console.error('Login failed:', error);
}
};
Permission configuration
Configure application permissions in your GitHub OAuth App:
GitHub OAuth scopes:
- user (scope) - Access user profile information
- user:email (scope) - Access user email addresses
- read:user (scope) - Read user profile information
- user:follow (scope) - Access follow/unfollow functionality
- public_repo (scope) - Access public repositories (optional)
- repo (scope) - Access all repositories (optional)