Skip to content

Commit

Permalink
[auth0-lock] v11.27.1 Add types for AuthResult & checkSession Options. (
Browse files Browse the repository at this point in the history
DefinitelyTyped#49808)

* [auth0-lock] Add types for AuthResult & checkSession Options.

* [auth0-lock] Add any interface for payload.
  • Loading branch information
xsv24 authored Dec 22, 2020
1 parent bf36f8c commit 5b373c2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 11 deletions.
55 changes: 53 additions & 2 deletions types/auth0-lock/auth0-lock-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@ lock.checkSession({}, function(error: auth0.Auth0Error, authResult: AuthResult):
}
});

lock.checkSession({
access_token: undefined,
connection_scope: undefined,
device: undefined,
nonce: undefined,
protocol: undefined,
request_id: undefined,
scope: undefined,
state: undefined,
param: undefined
}, function(error: auth0.Auth0Error, authResult: AuthResult): void {
if (error || !authResult) {
lock.show();
} else {
// user has an active session, so we can use the accessToken directly.
lock.getUserInfo(authResult.accessToken, function(error, profile) {
console.log(error, profile);
});
}
});

// Show supports UI arguments

const showOptions : Auth0LockShowOptions = {
Expand Down Expand Up @@ -269,18 +290,48 @@ const avatarOptions : Auth0LockConstructorOptions = {

new Auth0Lock(CLIENT_ID, DOMAIN, avatarOptions);

const authResult : AuthResult = {
const authResultWithUndefined : AuthResult = {
accessToken: 'fake_access_token',
expiresIn: 7200,
idToken: 'fake_id_token',
idTokenPayload: {
name: undefined,
nickname: undefined,
picture: undefined,
email: undefined,
email_verified: undefined,
aud: "EaQzyHt1Dy57l-r5iHcMeT-lh1fFZntg",
exp: 1494393724,
iat: 1494357724,
iss: "https://www.foo.com",
sub: "auth0|aksjfkladsf"
sub: "auth0|aksjfkladsf",
acr: undefined,
amr: undefined
},
refreshToken: undefined,
state: "923jf092j3.FFSDJFDSKLDF",
tokenType: 'Bearer'
};

const authResultFilled : AuthResult = {
accessToken: 'fake_access_token',
expiresIn: 7200,
idToken: 'fake_id_token',
idTokenPayload: {
name: "fake name",
nickname: "fake nickname",
picture: "https://www.fakeavatar.com/fake.png",
email: "fake@fake.com",
email_verified: true,
aud: "EaQzyHt1Dy57l-r5iHcMeT-lh1fFZntg",
exp: 1494393724,
iat: 1494357724,
iss: "https://www.foo.com",
sub: "auth0|aksjfkladsf",
acr: "http://schemas.openid.net/pape/policies/2007/06/multi-factor",
amr: ["mfa"]
},
refreshToken: "refresh_token",
state: "923jf092j3.FFSDJFDSKLDF",
tokenType: 'Bearer'
};
30 changes: 21 additions & 9 deletions types/auth0-lock/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Dan Caddigan <https://github.com/goldcaddy77>
// Larry Faudree <https://github.com/lfaudreejr>
// Will Caulfield <https://github.com/willcaul>
// Thomas Pearson <https://github.com/xsv24>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7

Expand Down Expand Up @@ -93,6 +94,7 @@ interface Auth0LockAuthParamsOptions {
request_id?: any;
scope?: string;
state?: string;
[key: string]: any; // Auth0 rules can use custom params.
}

interface Auth0LockAuthOptions {
Expand Down Expand Up @@ -174,31 +176,41 @@ interface Auth0LockShowOptions {
languageDictionary?: any;
}

interface Auth0IdTokenPayload {
name?: string;
nickname?: string;
picture?: string;
email?: string;
email_verified?: boolean;
aud: string;
exp: number;
iat: number;
iss: string;
sub: string;
acr?: string;
amr?: string[];
[key: string]: any;
}

interface AuthResult {
accessToken: string;
appState?: any;
expiresIn: number;
idToken: string;
idTokenPayload: {
aud: string;
exp: number;
iat: number;
iss: string;
sub: string;
};
idTokenPayload: Auth0IdTokenPayload;
refreshToken?: string;
scope?: string;
state: string;
tokenType: string;
}
}

interface Auth0LockStatic {
new (clientId: string, domain: string, options?: Auth0LockConstructorOptions): Auth0LockStatic;

// deprecated
getProfile(token: string, callback: (error: auth0.Auth0Error, profile: auth0.Auth0UserProfile) => void): void;
getUserInfo(token: string, callback: (error: auth0.Auth0Error, profile: auth0.Auth0UserProfile) => void): void;
checkSession(options: any, callback: (error: auth0.Auth0Error, authResult: AuthResult | undefined) => void): void;
checkSession(options: Auth0LockAuthParamsOptions, callback: (error: auth0.Auth0Error, authResult: AuthResult | undefined) => void): void;
// https://github.com/auth0/lock#resumeauthhash-callback
resumeAuth(hash: string, callback: (error: auth0.Auth0Error, authResult: AuthResult) => void): void;
show(options?: Auth0LockShowOptions): void;
Expand Down

0 comments on commit 5b373c2

Please sign in to comment.