Giter VIP home page Giter VIP logo

hello-github-oauth's Introduction

Hello GitHub OAuth

This is a 'Hello World' app to demonstrate a minimal working connection with GitHub OAuth for an ASP.NET Core 7.0 application (specifically v7.0.102).

This web app is based on the article Add GitHub OpenID Auth For ASP.NET Core Apps by Khalid Abuhakmeh which uses ASP.NET Core 5.0.

This app only claims access to public information for an account so I believe I can include the ClientSecret below without putting anybody's personal data at risk. However, if you do use the Client details below to authorize this app with your GitHub account I would still recommend you revoke access afterwards by going to GitHub Settings and revoking access for "Hello GitHub OAuth".

Expected Behaviour

  • Click on "my secret" on the homepage.
  • You should be presented with Authentication page with a "Sign in using GitHub" button.
  • After clicking on the button you will be asked if you want to "Authorise Hello GitHub OAuth" with a green "Authorize codybartfast" button.
  • If you authorize the app you should be redirected to the 'secret' page.

To Run This App Using My GitHub OAuth Registration

To authenticate using my OAuth registration run the following commands in the application root:

dotnet user-secrets set github:clientId "75dfc8f5ff877ffce7f2" --project HelloGithubOAuth.csproj
dotnet user-secrets set github:clientSecret "92a33c17e7c8c87ab69d0f63a66059b2daef8f84" --project HelloGithubOAuth.csproj

To Run This App Using Your Own GitHub OAuth Registration

Visit GitHub Developer Settings to register a new OAuth application. Use http://localhost:5291/ as the 'Homepage URL' and http://localhost:5291/signin-github as the 'Authorized callback URL'. After registering your application you can view the 'Client ID' of your registration and can create a Client Secret. Configure the App to use your details using:

dotnet user-secrets set github:clientId "<your client id>" --project HelloGithubOAuth.csproj
dotnet user-secrets set github:clientSecret "<your client secret>" --project HelloGithubOAuth.csproj

To Add GitHub OAuth To an Existing App

The base of this application was created using these commands:

dotnet new webapp -n HelloGithubOAuth
mv HelloGithubOAuth hello-github-oauth
cd hello-github-oauth

dotnet new page --name Signin --output Pages --namespace HelloGithubOAuth.Pages
dotnet new page --name Secret --output Pages --namespace HelloGithubOAuth.Pages
dotnet new gitignore

This commit shows all the changes that were made to that base project to enable GitHub OAuth and add a secured ('secret') page.

Do not use the same UserSecretId in your own project file. Instead use this command to add a new User Secrets Id before setting the ClientId and ClientSecret user secrets.

dotnet user-secrets init --project <Your Project Name>.csproj

For details see:

hello-github-oauth's People

Contributors

codybartfast avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.