Thursday, May 12, 2022

Setup username-token authentication for Gradle

 

What is github authentication?


Well as it sounds, github authentication is used for accessing github resources(repositories/registries). 

Also github offering various kind of authentication methods to authenticate a resource. You have to use one of them in most cases and unless the resources is not public.

Let’s have a look on authentication methods in github.
  • username - password authentication
  • ssh authentication
  • Token authentication 
  • SSO authentication

why we need token authentication for github?


So as we discussed there are few authentication methods in github. But, why we need token authentication with gradle?

The simplest answer is to access to github registry packages

In gradle, it is not supported to ssh or sso authentication. So we have to choose user-pass authentication or token authentication,
Under the best practices and security reasons best option is using token authentication.

Setting up Token authentication in github and gradle


Github:
  1. Verify your email address, if it hasn't been verified yet.
  2. In the upper-right corner of any page, click your profile photo, then click Settings.
  1. In the left sidebar, click Developer settings.

  1. Click Generate new token.
  1. Give your token a descriptive name.
  2. Select the scopes, or permissions, you'd like to grant this token. To use your token to access repositories from the command line, select repo.
  1. Click Generate token.
Setting up github token with gradle

To use github token in gradle you need to add it to gradle global properties

The global properties file should be located in your home directory:
  • On Windows: C:\Users\<you>\.gradle\gradle.properties
  • On Mac/Linux: /Users/<you>/.gradle/gradle.properties

Replace youre username and Token.

USERNAME="Your username"
TOKEN="Your password"


Now try to build your favorite gradle project.


No comments:

Post a Comment

Update openSSL to latest 1.1.1 version (1.1.1w)

  By the time(2024) one our system use this old OpenSSL version 1.1.1g and we are going to update it to latest version of 1.1.1 openSSL v...