From a52dade23ee75d9fd1c8577a0aca911b7c76d0bd Mon Sep 17 00:00:00 2001 From: AdvancedREI Date: Mon, 12 May 2014 17:50:58 -0700 Subject: [PATCH] Added Auth0 definitions for JS API and widget --- CONTRIBUTORS.md | 4 +- auth0.widget/auth0.widget-tests.ts | 18 +++++ auth0.widget/auth0.widget.d.ts | 48 +++++++++++++ auth0/auth0-tests.ts | 23 +++++++ auth0/auth0.d.ts | 107 +++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 auth0.widget/auth0.widget-tests.ts create mode 100644 auth0.widget/auth0.widget.d.ts create mode 100644 auth0/auth0-tests.ts create mode 100644 auth0/auth0.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f39e1f53d6ac9a..394f420bc35222 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,4 +1,4 @@ -# Contributors +# Contributors This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. @@ -22,6 +22,8 @@ All definitions files include a header with the author and editors, so at some p * [assert](https://github.com/Jxck/assert) (by [vvakame](https://github.com/vvakame)) * [async](https://github.com/caolan/async) (by [Boris Yankov](https://github.com/borisyankov)) * [Atom](https://atom.io/) (by [vvakame](https://github.com/vvakame)) +* [Auth0](https://auth0.com/) (by [Robert McLaws](https://github.com/advancedrei)) +* [Auth0.Widget](https://auth0.com/) (by [Robert McLaws](https://github.com/advancedrei)) * [aws-sdk-js](https://github.com/aws/aws-sdk-js) (by [midknight41](https://github.com/midknight41)) * [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm)) diff --git a/auth0.widget/auth0.widget-tests.ts b/auth0.widget/auth0.widget-tests.ts new file mode 100644 index 00000000000000..012e9b9769b4cb --- /dev/null +++ b/auth0.widget/auth0.widget-tests.ts @@ -0,0 +1,18 @@ +/// +/// + +var widget: Auth0WidgetStatic = new Auth0Widget({ + domain: 'mine.auth0.com', + clientID: 'dsa7d77dsa7d7', + callbackURL: 'http://my-app.com/callback', + callbackOnLocationHash: true +}); + +widget.signin({ + connections: ['facebook', 'google-oauth2', 'twitter', 'Username-Password-Authentication'], + icon: 'https://contoso.com/logo-32.png', + showIcon: true +}, + () => { + // The Auth0 Widget is now loaded. + }); diff --git a/auth0.widget/auth0.widget.d.ts b/auth0.widget/auth0.widget.d.ts new file mode 100644 index 00000000000000..6be138dcbbd8bb --- /dev/null +++ b/auth0.widget/auth0.widget.d.ts @@ -0,0 +1,48 @@ +// Type definitions for Auth0Widget.js +// Project: Auth0.com +// Definitions by: Robert McLaws +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + + +interface Auth0WidgetStatic { + new(params: Auth0Constructor): Auth0WidgetStatic; + + getClient(): Auth0Static; + getProfile(token: string, callback: Function): Auth0UserProfile; + parseHash(hash: string): Auth0DecodedHash; + reset(options: Auth0Options, callback?: Function): Auth0WidgetStatic; + signin(options: Auth0Options, widgetLoadedCallback?: Function, popupCallback?: Function): Auth0WidgetStatic; + signup(options: Auth0Options, callback: (error?: Auth0Error, profile?, id_token?, access_token?, state?) => any): Auth0WidgetStatic; + } + +interface Auth0Constructor extends Auth0ClientOptions { + assetsUrl?: string; + cdn?: string; + dict?: any; + } + +interface Auth0Options { + access_token?: string; + connections?: string[]; + container?: string; + enableReturnUserExperience?: boolean; + extraParameters?: any; + icon?: string; + protocol?: string; + request_id?: string; + scope?: string; + showIcon?: boolean; + showForgot?: boolean; + showSignup?: boolean; + state?: any; + userPwdConnectionName?: string; + username_style?: string; +} + +declare var Auth0Widget: Auth0WidgetStatic; + +declare module "Auth0Widget" { + export = Auth0Widget +} \ No newline at end of file diff --git a/auth0/auth0-tests.ts b/auth0/auth0-tests.ts new file mode 100644 index 00000000000000..9cd903b3069a9a --- /dev/null +++ b/auth0/auth0-tests.ts @@ -0,0 +1,23 @@ +/// + +var auth0 = new Auth0({ + domain: 'mine.auth0.com', + clientID: 'dsa7d77dsa7d7', + callbackURL: 'http://my-app.com/callback', + callbackOnLocationHash: true +}); + +auth0.login({ + connection: 'google-oauth2', + popup: true, + popupOptions: { + width: 450, + height: 800 + } +}, (err, profile, idToken, accessToken, state) => { + if (err) { + alert("something went wrong: " + err.message); + return; + } + alert('hello ' + profile.name); + }); diff --git a/auth0/auth0.d.ts b/auth0/auth0.d.ts new file mode 100644 index 00000000000000..939928b8e76b88 --- /dev/null +++ b/auth0/auth0.d.ts @@ -0,0 +1,107 @@ +// Type definitions for Auth0.js +// Project: Auth0.com +// Definitions by: Robert McLaws +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** This is the interface for the main Auth0 client. */ +interface Auth0Static { + + new(options: Auth0ClientOptions): Auth0Static; + changePassword(options: any, callback?: Function); + decodeJwt(jwt: string): any; + login(options: any, callback: (error, profile?, id_token?, access_token?, state?) => any); + loginWithPopup(options: Auth0LoginOptions, callback: (error, profile?, id_token?, access_token?, state?) => any); + loginWithResourceOwner(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?, id_token?, access_token?, state?) => any); + loginWithUsernamePassword(options: Auth0LoginOptions, callback: (error?: Auth0Error, profile?, id_token?, access_token?, state?) => any); + logout(query: string): void; + getConnections(callback?: Function) + getDelegationToken(targetClientId, id_token: string, options: any, callback: (error?: Auth0Error, delegationResult?: Auth0DelegationToken) => any): void; + getProfile(id_token: string, callback?: Function): Auth0UserProfile; + getSSOData(withActiveDirectories: any, callback?: Function); + parseHash(hash: string): Auth0DecodedHash; + signup(options: Auth0SignupOptions, callback: Function); + validateUser(options: any, callback: (error?: Auth0Error, valid?) => any); +} + +/** Represents constructor options for the Auth0 client. */ +interface Auth0ClientOptions { + clientID: string; + callbackURL: string; + callbackOnLoactionHash?: boolean; + domain: string; + forceJSONP?: boolean; +} + +/** Represents a normalized UserProfile. */ +interface Auth0UserProfile { + email: string; + family_name: string; + gender: string; + given_name: string; + locale: string; + name: string; + nickname: string; + picture: string; + user_id: string; + /** Represents one or more Identities that may be associated with the User. */ + identities: Auth0Identity[]; +} + +/** Represents */ +interface Auth0Identity { + access_token: string; + connection: string; + isSocial: boolean; + provider: string; + user_id: string; +} + +interface Auth0DecodedHash { + access_token: string; + id_token: string; + profile: Auth0UserProfile; + state: any; +} + +interface Auth0PopupOptions { + width: number; + height: number; +} + +interface Auth0LoginOptions { + auto_login?: boolean; + connection?: string; + email?: string; + username?: string; + password?: string; + popup?: boolean; + popupOptions?: Auth0PopupOptions; +} + +interface Auth0SignupOptions extends Auth0LoginOptions { + auto_login: boolean; +} + +interface Auth0Error { + code: any; + details: any; + name: string; + message: string; + status: any; +} + +/** Represents the response from an API Token Delegation request. */ +interface Auth0DelegationToken { + /** The length of time in seconds the token is valid for. */ + expires_in: string; + /** The JWT for delegated access. */ + id_token: string; + /** The type of token being returned. Possible values: "Bearer" */ + token_type: string; +} + +declare var Auth0: Auth0Static; + +declare module "Auth0" { + export = Auth0 +} \ No newline at end of file