Skip to content

Commit

Permalink
Added Auth0 definitions for JS API and widget
Browse files Browse the repository at this point in the history
  • Loading branch information
AdvancedREI committed May 13, 2014
1 parent 68fd50f commit a52dade
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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))
Expand Down
18 changes: 18 additions & 0 deletions auth0.widget/auth0.widget-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference path="../auth0/auth0.d.ts" />
/// <reference path="auth0.widget.d.ts" />

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.
});
48 changes: 48 additions & 0 deletions auth0.widget/auth0.widget.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Type definitions for Auth0Widget.js
// Project: Auth0.com
// Definitions by: Robert McLaws <https://github.com/advancedrei>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

/// <reference path="../auth0/auth0.d.ts" />


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
}
23 changes: 23 additions & 0 deletions auth0/auth0-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference path="../auth0/auth0.d.ts" />

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);
});
107 changes: 107 additions & 0 deletions auth0/auth0.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Type definitions for Auth0.js
// Project: Auth0.com
// Definitions by: Robert McLaws <https://github.com/advancedrei>
// 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
}

0 comments on commit a52dade

Please sign in to comment.