This repository was archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write TypeScript definition for library
- Loading branch information
1 parent
0636176
commit 3ce8b3f
Showing
6 changed files
with
126 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
declare class ClientOAuth2 { | ||
code: ClientOAuth2.CodeFlow; | ||
token: ClientOAuth2.TokenFlow; | ||
owner: ClientOAuth2.OwnerFlow; | ||
credentials: ClientOAuth2.CredentialsFlow; | ||
jwt: ClientOAuth2.JwtBearerFlow; | ||
|
||
constructor(options: ClientOAuth2.Options, request: ClientOAuth2.Request); | ||
|
||
createToken(data: ClientOAuth2.Data): ClientOAuth2.Token; | ||
createToken(accessToken: string, data: ClientOAuth2.Data): ClientOAuth2.Token; | ||
createToken(accessToken: string, refreshToken: string, data: ClientOAuth2.Data): ClientOAuth2.Token; | ||
createToken(accessToken: string, refreshToken: string, type: string, data: ClientOAuth2.Data): ClientOAuth2.Token; | ||
} | ||
|
||
declare namespace ClientOAuth2 { | ||
export interface Data { | ||
[key: string]: string | ||
} | ||
|
||
export interface Options { | ||
clientId?: string | ||
clientSecret?: string | ||
accessTokenUri?: string | ||
authorizationUri?: string | ||
redirectUri?: string | ||
scopes?: string | ||
state?: string | ||
body?: { | ||
[key: string]: string | string[]; | ||
}; | ||
query?: { | ||
[key: string]: string | string[]; | ||
}; | ||
headers?: { | ||
[key: string]: string | string[]; | ||
}; | ||
} | ||
|
||
export interface Request { | ||
(method: string, url: string, body: string, headers: { [key: string]: string | string[] }): Promise<{ status: number, body: string }>; | ||
} | ||
|
||
export interface RequestObject { | ||
url: string; | ||
headers?: { | ||
[key: string]: string | string[]; | ||
}; | ||
} | ||
|
||
export class Token { | ||
client: ClientOAuth2; | ||
data: Data; | ||
tokenType: string; | ||
accessToken: string; | ||
refreshToken: string; | ||
|
||
constructor(client: ClientOAuth2, data: Data); | ||
expiresIn(duration: number | Date): Date; | ||
sign<T extends RequestObject>(requestObj: T): T; | ||
refresh(options?: Options): Promise<Token>; | ||
expired(): boolean; | ||
} | ||
|
||
export class CodeFlow { | ||
constructor(client: ClientOAuth2); | ||
getUri(options?: Options): string; | ||
getToken(uri: string, options?: Options): Promise<Token>; | ||
} | ||
|
||
export class TokenFlow { | ||
constructor(client: ClientOAuth2); | ||
getUri(options?: Options): string; | ||
getToken(uri: string, options?: Options): Promise<Token>; | ||
} | ||
|
||
export class OwnerFlow { | ||
constructor(client: ClientOAuth2); | ||
getToken(username: string, password: string, options?: Options): Promise<Token>; | ||
} | ||
|
||
export class CredentialsFlow { | ||
constructor(client: ClientOAuth2); | ||
getToken(options?: Options): Promise<Token>; | ||
} | ||
|
||
export class JwtBearerFlow { | ||
constructor(client: ClientOAuth2); | ||
getToken(token: string, options?: Options): Promise<Token>; | ||
} | ||
} | ||
|
||
export = ClientOAuth2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters