On GitHub, your traffic data is only persisted for 2 weeks. There are mechanisms for getting around this. This project provides a reusable lib for persisting your repository data in a sqlite database file. The lib is also available as a Nuget package.

Repository

The repository has 3 apps:

All 3 apps use the lib GitHubMetaLib and if running from the same code locally, share the same sqlite database file.

The first 2 are run as a local user. You provided credentials for your GitHub login via MFA and it is just your repositories on GitHub that are interrogated for repository traffic data. The Console app just updates the database. The WPF provides for selections of repositories to be checked as well as for entering the PAT. Presentation there is tabular as well as graphical.

Data

The traffic data for selected repositories is presented in a summative manner (totals over the selected period) as well as daily values. Entities collected as per the repositories’ Traffic page are:

  • Number of Clones
  • Number of Cloners
  • Number of Views
  • Number of Viewers

Nuget

Whilst all three apps use the same lib, they can use a version of it published as package on GitHub. Indeed, the Release versions of the 3 apps use that whereas the Debug versions use the local source code for the lib.

The Blazor app

The Blazor app is designed to be multi-user and could be hosted on, for example, Azure. If running publicly, any user can select a hosted GitHub repository owner and see the data for repositories tha the owner has selected from their public repositories, and for which they have manually updated the data.

Admin and other users.

The first GitHub author to login using GitHub MFA to the Blazor app becomes the Admin owner. (Might improve on that later). Only the admin user can add/remove ordinary GitHub repository owners who at this time cannot be elevated to Admin.

An ordinary owner can login via GitHub and:

  • Select repositories of their’s to be scanned for traffic data
  • Remove such.
  • Update scans for their selected repositories.

NB: There is not a current timely auto-scan of repositories although that might be a future option.

GitHub PAT access

This is required for getting the repository traffic data from GitHub by the Console and WDF apps.

  • Recommended: classic PAT with repo scope.
  • If all monitored repositories are public, public_repo may be enough.
  • Token user must have at least push/write access to each monitored repository to read traffic endpoints.
  • Fine-grained tokens may return 403 Resource not accessible by personal access token for traffic APIs.

… Use a Classic PAT

…Set PAT scope to repo as is required for traffic API access.

PowerShell example for Console App:

$env:GITHUB_TOKEN="ghp_your_classic_pat_here"
dotnet run --project .\GitHubMetaConsole\GitHubMetaConsole.csproj

Nb: In the WPF app you can enter the PAT in the UI. It is stored encrypted in Appsettings.

Blazor Credentials

Blazor’s Client ID and Client Secret: these only identify the app to GitHub, so it can ask GitHub to sign a user in. On their own they can’t read any repo data.

Blazor sign-in flow:

  • Ordinary users can view hosted data for all owners.
  • An Owner clicks Sign in with GitHub.
  • GitHub checks your password and MFA, then hands the app a token for your account.
  • The app checks that 2FA is on and that you’re in the Owners list.
  • It keeps the token in memory and uses it for Discover, Track and Sync.
  • Once that token is gone (after Log out or a server restart), nothing can sync until someone signs in again.
  • Public visitors only ever see data already in the database.

Setup First

Before actioning the above you need to embed the ClientId and ClientSecret on the machine on which the Blazor app runs.

For a Blazor app, Client ID / Client Secret come from the identity provider (not from .NET). Most common setups:

Microsoft Entra ID (Azure AD)

  1. Go to Azure Portal → Microsoft Entra ID → App registrations.
  2. Click New registration.
  3. Set name, account type, and redirect URI (for server auth typically https://localhost:/signin-oidc).
  4. After create: • Application (client) ID = your Client ID.
  5. Go to Certificates & secrets → New client secret.
  6. Copy the secret value immediately (shown once) = your Client Secret.

GitHub OAuth app

  1. GitHub → Settings → Developer settings → OAuth Apps.
  2. Click New OAuth App.
  3. Set: • Homepage URL: https://localhost: • Authorization callback URL: https://localhost:/signin-github
  4. Create app.
  5. Copy: • Client ID • Generate/copy Client Secret

Important:

  • The callback URL must exactly match what the app uses (/signin-github in typical ASP.NET Core GitHub auth).
    • If local port changes, update the OAuth app callback URL too.
  • From the repository root on the dev machine run:
    dotnet user-secrets set "GitHub:ClientId" "<your-client-id>" --project .\GitHubMetaLib\GitHubMetaLib.csproj
    dotnet user-secrets set "GitHub:ClientSecret" "<your-client-secret>" --project .\GitHubMetaLib\GitHubMetaLib.csproj
    
  • Now start/restart the Blazor app.

Alt: Can use Appsettings.json but not advisable:

"Authentication": {
  "GitHub": {
    "ClientId": "your-client-id",
    "ClientSecret": "your-client-secret"
  }
}

Further

There is detailed documents generated during the development process at GitHubMeta docs


 TopicSubtopic
<  Prev:   Blazor Apps
   
 This Category Links 
Category:Application Dev Index:Application Dev