Add Auth to SVAPI

This commit is contained in:
Brendan Lane 2020-12-13 19:33:21 -05:00
parent b4672cece6
commit b9b7b267f4
9 changed files with 74 additions and 32 deletions

View File

@ -19,5 +19,5 @@ You can [email](mailto:me@brndnln.dev?cc=bluebeargreen2@gmail.com&subject=%F0%9F
us about your findings, just don't send them to us over Discord, post them in any public places, etc. us about your findings, just don't send them to us over Discord, post them in any public places, etc.
Basically don't be a moron. You can also tell us that you sent us an email over at [our bounties site](https://bounties.vexi.cc) (just wait until its done) Basically don't be a moron. You can also tell us that you sent us an email over at [our bounties site](https://bounties.vexi.cc) (just wait until its done)
> Happy Hacking! Happy Hacking!
> \- Brendan Lane \- Brendan Lane

View File

@ -3,8 +3,10 @@
import User from './modules/User' import User from './modules/User'
import Group from './modules/Group' import Group from './modules/Group'
import Auth from './modules/Auth'
export { export {
User, User,
Group Group,
Auth
} }

View File

@ -59,6 +59,26 @@ class Auth {
return this.urlReturn return this.urlReturn
} }
} }
public async requestToken (redirect: string): Promise<any> {
return await new Promise((resolve, reject) => {
axios.get(`${authURL}/requestToken`, {
params: {
grant_type: 'authorization_code',
code: this.code,
redirect_uri: redirect,
client_id: this.appid,
client_secret: this.appsecret
}
})
.then((response) => {
resolve(response.data)
})
.catch((error) => {
reject(error)
})
})
}
} }
export default Auth export default Auth

5
typings/main.d.ts vendored
View File

@ -1,5 +1,4 @@
// SpookVooper API - src/main.ts
// Written by Brendan Lane - https://brndnln.dev/
import User from './modules/User' import User from './modules/User'
import Group from './modules/Group' import Group from './modules/Group'
export { User, Group } import Auth from './modules/Auth'
export { User, Group, Auth }

17
typings/modules/Auth.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
import { AuthConfig } from './types/Types'
declare class Auth {
private readonly appsecret
private readonly code
private readonly appid
urlReturn: string
constructor (config: AuthConfig);
get clientsecret (): string;
set clientsecret (clientsecret: string);
get authcode (): string;
set authcode (authcode: string);
get clientid (): string;
set clientid (clientid: string);
genLink (redirect: string, scope: string, state?: string): string;
requestToken (redirect: string): Promise<any>;
}
export default Auth

View File

@ -1,14 +1,13 @@
import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types' import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types'
declare class Group { declare class Group {
// eslint-disable-next-line @typescript-eslint/prefer-readonly private readonly accountid
private accountid constructor (svid: string);
constructor (svid: string) getGroup (): Promise<any>;
getGroup (): Promise<any> sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise<any> doesGroupExist (): Promise<any>;
doesGroupExist (): Promise<any> getGroupMembers (): Promise<any>;
getGroupMembers (): Promise<any> hasGroupPermission (user: GroupMember, permission: string): Promise<any>;
hasGroupPermission (user: GroupMember, permission: string): Promise<any> get svid (): string;
get svid (): string set svid (svid: string);
set svid (svid: string)
} }
export default Group export default Group

View File

@ -1,21 +1,19 @@
import { CreditAmount, PaymentEntity, SVStockTicker } from './types/Types' import { CreditAmount, PaymentEntity, SVStockTicker } from './types/Types'
import { ConfigUser } from './interfaces/Interfaces' import { ConfigUser } from './interfaces/Interfaces'
declare class User { declare class User {
// eslint-disable-next-line @typescript-eslint/prefer-readonly private readonly accountid
private accountid private readonly authkey
// eslint-disable-next-line @typescript-eslint/prefer-readonly constructor (config: ConfigUser);
private authkey getUser (): Promise<any>;
constructor (config: ConfigUser) getUsername (): Promise<any>;
getUser (): Promise<any> getBalance (): Promise<any>;
getUsername (): Promise<any> hasDiscordRole (role: string): Promise<any>;
getBalance (): Promise<any> getDiscordRoles (): Promise<any>;
hasDiscordRole (role: string): Promise<any> sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any>;
getDiscordRoles (): Promise<any> getStockOffers (ticker: SVStockTicker): Promise<any>;
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string): Promise<any> buyStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>;
getStockOffers (ticker: SVStockTicker): Promise<any> sellStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>;
buyStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any> cancelOffer (orderid: number): Promise<any>;
sellStock (ticker: SVStockTicker, amount: number, price: CreditAmount): Promise<any>
cancelOffer (orderid: number): Promise<any>
get apikey (): string; get apikey (): string;
set apikey (apikey: string); set apikey (apikey: string);
get svid (): string; get svid (): string;

View File

@ -17,6 +17,12 @@ export interface ConfigUser {
svid: string svid: string
apikey?: string apikey?: string
} }
export interface EntityGroup { export interface EntityGroup {
svid: string svid: string
} }
export interface AuthConfig {
clientid: string
clientsecret: string
}

View File

@ -1,6 +1,7 @@
import { EntityUser } from './../interfaces/Interfaces' import { EntityUser, AuthConfig as AuthConfigInt } from './../interfaces/Interfaces'
export declare type CreditAmount = string | number export declare type CreditAmount = string | number
export declare type PaymentEntity = string | EntityUser export declare type PaymentEntity = string | EntityUser
export declare type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X' export declare type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X'
export declare type AuthEntity = EntityUser export declare type AuthEntity = EntityUser
export declare type GroupMember = string | EntityUser export declare type GroupMember = string | EntityUser
export declare type AuthConfig = AuthConfigInt