npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

teko-oauth2-react-native

v0.1.0

Published

Teko Identity OAuth 2 Javascript Library for react native

Readme

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 ? (
        <View>
          <TouchableOpacity style={{ padding: 8, backgroundColor: 'lightblue' }} onPress={onLoginWithGoogle}>
            <Text>{'Login with google'}</Text>
          </TouchableOpacity>
        </View>
      ) : (
        <TouchableOpacity style={{ marginTop: 16, padding: 8, backgroundColor: 'lightblue' }} onPress={onLogout}>
          <Text>{'Logout'}</Text>
        </TouchableOpacity>
      )}
    </View>
  );
};

Installation

Add package to project by using git repo

# yarn
yarn add ssh://[email protected]:teko-vn/tekoid-react-native.git

# npm
npm install ssh://[email protected]:teko-vn/tekoid-react-native.git

Initiate the client

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

TekoID.init({
  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.
  setLoggedInState(TekoId.isLoggedIn());
});

which returns a promise and resolve after finish initiating.

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

Usage

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.


TekoID.user

.isLoggedIn()

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

.logout()

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

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

.loginWithGoogle()

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

.loginWithPhone(phoneNumber)

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

.verifyOtp(otp)

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

.getAccessToken()

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.

.getUserInfo()

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 protected]',
  phone_number: '0123456789',
  birthday: '2000-12-31',
  address: '',

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

.getUserScopes()

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.

.setOnAuthStateChangedListener(listener)

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

Todo

  • [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