diff --git a/types/react-native-auth0/index.d.ts b/types/react-native-auth0/index.d.ts new file mode 100644 index 0000000000..45016da9ca --- /dev/null +++ b/types/react-native-auth0/index.d.ts @@ -0,0 +1,171 @@ +// Type definitions for react-native 1.2 +// Project: https://github.com/auth0/react-native-auth0 +// Definitions by: Andrea Ascari +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +/** + * Auth + */ + +export interface AuthorizationUrlParams { + responseType: string; + redirectUri: string; + state: string; +} + +export interface CreateUserParams { + 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; + createUser(user: CreateUserParams): Promise; + exchange(params: ExchangeParams): Promise; + logoutUrl(params: LogoutParams): string; + passwordRealm(params: PasswordRealmParams): Promise; + + refreshToken(params: RefreshTokenParams): Promise; + revoke(params: RevokeParams): Promise; + userInfo(params: UserInfoParams): Promise; +} + +/** + * Users + */ +export interface Auth0User { + 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 { + id: string; + metadata: T; +} + +export class Users { + constructor(options: UsersOptions); + /* tslint:disable-next-line no-unnecessary-generics */ + getUser(parameters: GetUserParams): Promise>; + patchUser( + parameters: PatchUserParams + ): Promise>; +} + +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; + clearSession(parameters: ClearSessionParams): Promise; +} + +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; +} diff --git a/types/react-native-auth0/react-native-auth0-tests.ts b/types/react-native-auth0/react-native-auth0-tests.ts new file mode 100644 index 0000000000..53eca829eb --- /dev/null +++ b/types/react-native-auth0/react-native-auth0-tests.ts @@ -0,0 +1,66 @@ +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.users("token").getUser({ id: "userId" }); + +auth0.users("token").patchUser<{ firstName: string; lastName: string }>({ + id: "userId", + metadata: { firstName: "John", lastName: "Dow" } +}); diff --git a/types/react-native-auth0/tsconfig.json b/types/react-native-auth0/tsconfig.json new file mode 100644 index 0000000000..f694a107be --- /dev/null +++ b/types/react-native-auth0/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "target": "es6", + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "react-native-auth0-tests.ts"] +} diff --git a/types/react-native-auth0/tslint.json b/types/react-native-auth0/tslint.json new file mode 100644 index 0000000000..fd90cce501 --- /dev/null +++ b/types/react-native-auth0/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + // Lowercase `object` is available in TypeScript 2.2 only. + "ban-types": false + } +}