Merge pull request #23533 from ascariandrea/react-native-auth0

Created react-native-auth0 types
This commit is contained in:
Daniel Rosenwasser
2018-03-07 00:30:39 -08:00
committed by GitHub
4 changed files with 258 additions and 0 deletions

170
types/react-native-auth0/index.d.ts vendored Normal file
View File

@@ -0,0 +1,170 @@
// Type definitions for react-native-auth0 1.2
// Project: https://github.com/auth0/react-native-auth0
// Definitions by: Andrea Ascari <https://github.com/ascariandrea>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
/**
* Auth
*/
export interface AuthorizationUrlParams {
responseType: string;
redirectUri: string;
state: string;
}
export interface CreateUserParams<T> {
email: string;
username?: string;
password: string;
connection: string;
metadata?: T;
}
export interface CreateUserResponse {
Id: string;
emailVerified: boolean;
email: string;
}
export interface ExchangeParams {
code: string;
redirectUri: string;
verifier: string;
}
export interface LogoutParams {
federated: boolean;
clientId?: string;
returnTo?: string;
}
export interface PasswordRealmParams {
username: string;
password: string;
realm: string;
audience?: string;
scope?: string;
}
export interface PasswordRealmResponse {
accessToken: string;
expiresIn: number;
idToken: string;
scope: string;
tokenType: "Bearer";
}
export interface RefreshTokenParams {
refreshToken: string;
scope?: string;
}
export interface RevokeParams {
refreshToken: string;
}
export interface UserInfoParams {
token: string;
}
export interface UserInfo {
email: string;
emailVerified: boolean;
name: string;
nickname: string;
picture: string;
sub: string;
updatedAt: string;
}
export class Auth {
authorizationUrl(params: AuthorizationUrlParams): string;
/* tslint:disable-next-line no-unnecessary-generics */
createUser<T>(user: CreateUserParams<T>): Promise<CreateUserResponse>;
exchange(params: ExchangeParams): Promise<string>;
logoutUrl(params: LogoutParams): string;
passwordRealm(params: PasswordRealmParams): Promise<PasswordRealmResponse>;
refreshToken(params: RefreshTokenParams): Promise<any>;
revoke(params: RevokeParams): Promise<any>;
userInfo(params: UserInfoParams): Promise<UserInfo>;
}
/**
* Users
*/
export interface Auth0User<T> {
created_at: string;
email: string;
emailVerified: boolean;
identities: any[];
last_ip?: string;
last_login?: string;
logins_count: number;
name: string;
nickname: string;
picture?: string;
updated_at: string;
userId: string;
userMetadata?: T;
}
export interface GetUserParams {
id: string;
}
export interface PatchUserParams<T> {
id: string;
metadata: T;
}
export class Users {
constructor(options: UsersOptions);
/* tslint:disable-next-line no-unnecessary-generics */
getUser<T>(parameters: GetUserParams): Promise<Auth0User<T>>;
patchUser<T>(parameters: PatchUserParams<T>): Promise<Auth0User<T>>;
}
export const users: Users;
/**
* Web Auth
*/
export interface AuthorizeParams {
state?: string;
nonce?: string;
audience?: string;
scope?: string;
}
export interface ClearSessionParams {
federated: boolean;
}
export class WebAuth {
authorize(parameters: AuthorizeParams): Promise<any>;
clearSession(parameters?: ClearSessionParams): Promise<any>;
}
export interface UsersOptions {
baseUrl: Options["domain"];
token: string;
}
export interface Options {
domain: string;
clientId: string;
}
/**
* Auth0
*/
export default class Auth0 {
auth: Auth;
webAuth: WebAuth;
constructor(options: Options);
users(token: string): Users;
}

View File

@@ -0,0 +1,67 @@
import Auth0, { UserInfo } from "react-native-auth0";
const auth0 = new Auth0({
domain: "definitely-typed",
clientId: "definitely-typed"
});
auth0.auth.createUser({
email: "me@example.com",
username: "johndoe",
password: "password",
connection: "db-connection"
});
auth0.auth.authorizationUrl({
responseType: "json",
redirectUri: "http://localhost:3000",
state: "my-state"
});
auth0.auth.exchange({
code: "my-code",
redirectUri: "http://localhost:3000",
verifier: "verifier"
});
auth0.auth.logoutUrl({
federated: true,
clientId: "client-id",
returnTo: "http://localhost:3000"
});
auth0.auth.passwordRealm({
username: "me@example.com",
password: "password",
realm: "realm",
audience: "user-info"
});
auth0.auth.refreshToken({
refreshToken: "refresh-token",
scope: "openid"
});
auth0.auth.revoke({
refreshToken: "refresh-token"
});
auth0.auth.userInfo({
token: "token"
});
auth0.webAuth.authorize({
state: "state",
nonce: "nonce",
scope: "openid"
});
auth0.webAuth.clearSession({ federated: false });
auth0.webAuth.clearSession();
auth0.users("token").getUser({ id: "userId" });
auth0.users("token").patchUser<{ firstName: string; lastName: string }>({
id: "userId",
metadata: { firstName: "John", lastName: "Dow" }
});

View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"target": "es6",
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "react-native-auth0-tests.ts"]
}

View File

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