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 🙏

© 2024 – Pkg Stats / Ryan Hefner

token-who-am-i-action

v1.0.9

Published

Retrieve identity information behind the GitHub token.

Downloads

293

Readme

token-who-am-i-action

Build Test ESLint CodeQL

As a GitHub Actions author, have you received GitHub token and tried to act on behave of the identity behind that token without knowing who that was? This GitHub Action helps you retrieve the identity information behind a GitHub token.

The information available from outputs:

  1. login: It's commonly known as the username, e.g. my login is CatChen. When it's a bot (aka a GitHub App) login has a [bot] suffix, e.g. github-actions[bot].
  2. global-id: It's a unique id across all different GitHub object types. It's mainly used in GraphQL's ID type. It matches node_id field in some REST API.
  3. id: A user or bot's id in the users table. A bot will have a different id from the bots table but it's rarely used.
  4. name: A user or bot's display name. It's optional for users but not for bots.
  5. email: A user's email if the user chose to make it visible to the public, or a bot's email constructed by GitHub's rules, e.g. 41898282+github-actions[bot]@users.noreply.github.com.
  6. type: Either User or Bot. Other less common types are not supported.
  7. app-slug: The bot's username that's used in it's URL. It doesn't have the [bot] suffix. That's how it's different from login.
  8. scopes: The user's permission scopes, e.g. read:org, repo. It's only available if the token is a classic PAT (Personal Access Token). It's not available for fine-grained PAT.

Usage as a Reusable Action

When writing a composite action, use this action as a step to retrieve a token's identity information:

runs:
  using: 'composite'
  steps:
    - uses: CatChen/token-who-am-i-action@v1
      id: token-who-am-i
      with:
        github-token: ${{ inputs.github-token }}

    - shell: bash
      env:
        LOGIN: ${{ steps.token-who-am-i.outputs.login }}
        GLOBAL_ID: ${{ steps.token-who-am-i.outputs.global-id }}
        ID: ${{ steps.token-who-am-i.outputs.id }}
        NAME: ${{ steps.token-who-am-i.outputs.name }}
        EMAIL: ${{ steps.token-who-am-i.outputs.email }}
        TYPE: ${{ steps.token-who-am-i.outputs.type }}
        APP_SLUG: ${{ steps.token-who-am-i.outputs.app-slug }}
        SCOPES: ${{ steps.token-who-am-i.outputs.scopes }}
      run: |
        echo "Login is $LOGIN"
        echo "Global id is $GLOBAL_ID"
        echo "Id is $ID"
        echo "Name is $NAME"
        echo "Email is $EMAIL"
        echo "Type is $TYPE"
        echo "App slug is $APP_SLUG"
        echo "Scopes are $SCOPES"

Usage as a JavaScript Package

When creating a JavaScript action, install the token-who-am-i-action package and use it to get the same information.

npm i token-who-am-i-action

Use npm from above or yarn from below to install the token-who-am-i-action package.

yarn add token-who-am-i-action

Import tokenWhoAmI function from the package and call it to retrieve the token identity information:

import { tokenWhoAmI } from 'token-who-am-i-action';

const me = await tokenWhoAmI(githubToken);

const {
  login,
  globalId,
  type,
} = me;

if (me.type === 'User') {
  const {
    id,
    name,
    email,
    scopes,
  } = me;
} else if (me.type === 'Bot') {
  const {
    appSlug,
    id,
    name,
    email,
  } = me;
}