add types for discourse-sso

Signed-off-by: Arnav Gupta <arnav@codingblocks.com>
This commit is contained in:
Arnav Gupta
2018-05-12 15:22:49 +05:30
parent a68f617d89
commit b1e3ed6ea9
4 changed files with 69 additions and 0 deletions

View File

@@ -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)
}

30
types/discourse-sso/index.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for discourse-sso 1.0
// Project: https://github.com/ArmedGuy/discourse_sso_node
// Definitions by: Arnav Gupta <https://github.com/championswimmer>
// 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 {
export 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

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"discourse-sso-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }