Skip to content

Commit

Permalink
Мелкие правки
Browse files Browse the repository at this point in the history
  • Loading branch information
JoCat committed Apr 26, 2021
1 parent 0b8afef commit 51539c2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/api/requests/AuthRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AuthRequest extends AbstractRequest {

async invoke(data: AuthRequestData): Promise<ResponseData> {
const provider = App.AuthManager.getAuthProvider()
return await provider.emit(data.login, data.password)
return await provider.auth(data.login, data.password)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/auth/authProviders/AbstractAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import { ResponseData } from "../../api/types/Response"
import { AbstractProvider } from "../AbstractProvider"
import { AcceptAuthProvider } from "./AcceptAuthProvider"

export abstract class AbstractAuthProvider extends AbstractProvider {
abstract emit(...args: any[]): PromiseOr<ResponseData>
abstract auth(login: string, password: string): PromiseOr<AuthResponseData>

public static getDefaultConfig(): AbstractAuthProviderConfig {
return {
Expand All @@ -38,3 +39,6 @@ export interface AuthResponseData extends ResponseData {
userUUID: string
accessToken: string
}

// TODO Указание доп.параметров для запуска клиента при использовании различных провайдеров
// Для работы Authlib
5 changes: 2 additions & 3 deletions src/auth/authProviders/AcceptAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

import { v4, v5 } from "uuid"

import { ResponseData } from "../../api/types/Response"
import { AbstractAuthProvider } from "./AbstractAuthProvider"
import { AbstractAuthProvider, AuthResponseData } from "./AbstractAuthProvider"

export class AcceptAuthProvider extends AbstractAuthProvider {
static type = "accept"

sessionsDB = new Map()

emit(username: string): ResponseData {
auth(username: string): AuthResponseData {
const data = {
username,
userUUID: v5(username, "814f98b5-f66d-4456-87dc-f4eed8f6ca73"),
Expand Down
2 changes: 1 addition & 1 deletion src/auth/authProviders/MojangAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AbstractAuthProvider, AuthResponseData } from "./AbstractAuthProvider"
export class MojangAuthProvider extends AbstractAuthProvider {
static type = "mojang"

async emit(login: string, password: string): Promise<AuthResponseData> {
async auth(login: string, password: string): Promise<AuthResponseData> {
const data = JSON.stringify({
agent: {
name: "Minecraft",
Expand Down
4 changes: 2 additions & 2 deletions src/auth/authProviders/RejectAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import { App } from "../../LauncherServer"
import { AbstractAuthProvider, AbstractAuthProviderConfig } from "./AbstractAuthProvider"
import { AbstractAuthProvider, AbstractAuthProviderConfig, AuthResponseData } from "./AbstractAuthProvider"

export class RejectAuthProvider extends AbstractAuthProvider {
static type = "reject"
Expand All @@ -27,7 +27,7 @@ export class RejectAuthProvider extends AbstractAuthProvider {
(App.ConfigManager.getConfig().auth.authProvider as RejectAuthProviderConfig).message || "Auth rejected",
}

emit(): any {
auth(): AuthResponseData {
throw {
code: 200,
message: this.config.message,
Expand Down

0 comments on commit 51539c2

Please sign in to comment.