diff --git a/types/discourse-sso/discourse-sso-tests.ts b/types/discourse-sso/discourse-sso-tests.ts new file mode 100644 index 0000000000..efe7eba95b --- /dev/null +++ b/types/discourse-sso/discourse-sso-tests.ts @@ -0,0 +1,16 @@ +import * as discourseSSO from 'discourse-sso'; +const sso = new discourseSSO('sso secret string'); + +if (sso.validate('payload', 'sig')) { + const nonce = sso.getNonce('payload'); + + const userParams: discourseSSO.UserParams = { + nonce, + external_id: '1', + email: 'omg@mail.com', + username: 'myuser', + name: 'This Guy' + }; + + const loginString: string = sso.buildLoginString(userParams); +} diff --git a/types/discourse-sso/index.d.ts b/types/discourse-sso/index.d.ts new file mode 100644 index 0000000000..b8030e0735 --- /dev/null +++ b/types/discourse-sso/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for discourse-sso 1.0 +// Project: https://github.com/ArmedGuy/discourse_sso_node +// Definitions by: Arnav Gupta +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class DiscourseSSO { + constructor(ssoSecret: string); + validate(payload: string, sig: string): boolean; + getNonce(payload: string): string; + buildLoginString(params: DiscourseSSO.UserParams): string; +} + +declare namespace DiscourseSSO { + interface UserParams { + nonce: string; + external_id: string; + email: string; + admin?: boolean; + moderator?: boolean; + username?: string; + name?: string; + avatar_url?: string; + add_groups?: string[]; + remove_groups?: string[]; + } +} +export = DiscourseSSO; diff --git a/types/discourse-sso/tsconfig.json b/types/discourse-sso/tsconfig.json new file mode 100644 index 0000000000..a0f1edbad5 --- /dev/null +++ b/types/discourse-sso/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "discourse-sso-tests.ts" + ] +} diff --git a/types/discourse-sso/tslint.json b/types/discourse-sso/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/discourse-sso/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }