GitHub Login Method
GitHub login method is a simple way to allow users to login to your application using their GitHub account. On login user will be shown a GitHub login button. When the user clicks on the button, the user will be redirected to GitHub’s login page.
After successful login, the user will be redirected back to the application with a session token.
Setup GitHub authentication
To use GitHub login method, you need to create a GitHub OAuth App. To create a GitHub OAuth App, follow the steps below:
Go to GitHub Developer Settings and click on “New OAuth App” button.
Fill in the details for your application. In the field
Homepage URLenterhttp://127.0.0.1:500. In the fieldAuthorization callback URLenterhttp://127.0.0.1:5000/github/callback.After creating the app, you will get a
Client IDandClient Secret. Save them as an environment variable in your application. For example, in a.envfile:GITHUB_CLIENT_ID=your-client-id GITHUB_CLIENT_SECRET=your-client-secret
Configure GitHub login method
To configure GitHub login method, you need to use the set_login_method method:
import nerfw
if __name__ == "__main__":
app = nerfw.NerFW()
app.set_login_method("github")
GitHub login method parameters
If you want to set a list of allowed users, you can use the set_allowed_users method:
import nerfw
if __name__ == "__main__":
app = nerfw.NerFW()
app.set_login_method("github")
app.set_allowed_users(["user1", "user2"])
User will be rejected if their GitHub username is not in the list of allowed users.