Teko Identity OAuth 2 Javascript Library for react native
Last updated 3 months ago by tu.nb .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install teko-oauth2-react-native 
SYNC missed versions from official npm registry.

Teko Identity OAuth 2 Javascript Library for expo/react native app

A Javascript Library for integrate Teko Identity OAuth 2 to expo/react native application.

Getting started

import TekoID from 'teko-oauth2-react-native';

const App = props => {
  return (
    <View style={styles.container}>
      {!isLoggedIn ? (
          <TouchableOpacity style={{ padding: 8, backgroundColor: 'lightblue' }} onPress={onLoginWithGoogle}>
            <Text>{'Login with google'}</Text>
      ) : (
        <TouchableOpacity style={{ marginTop: 16, padding: 8, backgroundColor: 'lightblue' }} onPress={onLogout}>


Add package to project by using git repo

# yarn
yarn add ssh://git@github.com:teko-vn/tekoid-react-native.git

# npm
npm install ssh://git@github.com:teko-vn/tekoid-react-native.git

Initiate the client

import TekoID from 'teko-oauth2-react-native';

  clientId: 'your-iam-client-id',
  googleClientId: 'your-google-client-id',
  scopes: ['your', 'scopes'],
  oauthDomain: 'https://oauth.develop.tekoapis.net',
  identityDomain: 'https://identity.develop.tekoapis.net',
}).then(() => {
  // The initial phase is finish.
  // Now you can do your logic.

which returns a promise and resolve after finish initiating.

For more integrate details, please refers to this sample project.


async TekoID.init(configs)

configs key Type Default value Required
clientId string Y
googleClientId string Y
scopes [string] []
oauthDomain string https://oauth.tekoapis.com
identityDomain string https://identity.tekoapis.com
useNativeLogIn boolean false
  • clientId: the ID of your client which you registered in Identity Teko.
  • googleClientId: the Google client id of your app for logging in with Google.
  • scopes: the scopes of your client.
  • oauthDomain: the oauth domain to use SDK.
  • identityDomain: the indentity domain to use SDK.
  • useNativeLogIn: whether app use native logg in method or not (by browser).

NOTE: For development environment, please specific oauthDomain to https://oauth.develop.tekoapis.net and identityDomain to https://identity.develop.tekoapis.net

NOTE: TekoID.init() function is an async function.



Return true if user is logged in, false if not.


Clear current user's auth state in order to log user out.

Call this function when user click to Logout button in your application.


Log in with google by expo-google-sign-in if useNativeLogIn is true, otherwise, use expo-google-app-auth


Request a OTP number, which is sent to your phone for verify user.


Authenticate user by verify given otp (Requested with loginWithPhone method)


Get logged user's current access token.

Return a string which is current user's access token if user is logged. null if user is not logged.


Get current user's general information.

Return object which includes current user's information. Error will be thrown if user is not logged in.

  • With openid scope, id_token will return with fields: sub, name, picture, updated_at.

  • With addition profile scope, id_token will return with addition fields: email, phone_number, birthday, address.

  • With addition read:permissions scope, id_token will return with addition fields: roles, permissions, meta_data.

Return value example (with openid, profile, read:permissions included in scopes):

  at_hash: 'MIAbeb9-aBBfL1B3XVbF-A',
  aud: ['public-sample-client'],
  auth_time: 1557287614,
  exp: 1557291215,
  iat: 1557287615,
  iss: 'https://dev-id.teko.vn/',

  sub: '1',
  name: 'User Name',
  picture: 'https://domain.com/avatar_url.jpg',
  updated_at: '2019-12-31 00:00:00',

  email: 'email@teko.vn',
  phone_number: '0123456789',
  birthday: '2000-12-31',
  address: '',

  roles: ['string'],
  permissions: ['string'],
  meta_data: {
    key: 'value'


Get logged user's scopes.

Return array of string which is current user's scopes if user is logged. [] if user is not logged.

Return value example:

['openid', 'profile'];

NOTE: This scopes may different with the scopes you defined when init. Because the scopes may be able to access by your app, but not for the current user (the user denied the app for access his/her data). If you want to use scopes in order to display correct UI, please uses this scopes value.

.refreshAccessToken(listener: OnRefreshAccessTokenListener)

Refresh current access token:

  • If current refresh token is expire or invalid, TekoID will call logout method.
  • If refresh successfule, TekoID will call listener for client can continue process.


Register a listener, which will be called when auth state changed (eg: login success, call logout method)


  • [x] Check authentication state
  • [x] Login with google
  • [x] Logout
  • [x] Get access token
  • [x] Get use info
  • [x] Login by OTP
  • [x] Expiration date
  • [x] Refresh access token
  • [ ] Login with native method

Current Tags

  • 0.1.0                                ...           latest (3 months ago)

1 Versions

  • 0.1.0                                ...           3 months ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |