mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-03 18:38:29 +02:00
minor helper fixes (#756)
Reviewed-on: https://gitea.com/gitea/tea/pulls/756 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:

committed by
techknowlogick

parent
9cb0d8baa1
commit
c5f398dcd2
@ -157,7 +157,7 @@ func OAuthLoginWithFullOptions(opts OAuthOptions) error {
|
|||||||
if strings.Contains(err.Error(), "no authorization code") ||
|
if strings.Contains(err.Error(), "no authorization code") ||
|
||||||
strings.Contains(err.Error(), "redirect_uri") ||
|
strings.Contains(err.Error(), "redirect_uri") ||
|
||||||
strings.Contains(err.Error(), "redirect") {
|
strings.Contains(err.Error(), "redirect") {
|
||||||
fmt.Println("\n❌ Error: Redirect URL not registered in Gitea")
|
fmt.Println("\nError: Redirect URL not registered in Gitea")
|
||||||
fmt.Println("\nTo fix this, you need to register the redirect URL in Gitea:")
|
fmt.Println("\nTo fix this, you need to register the redirect URL in Gitea:")
|
||||||
fmt.Printf("1. Go to your Gitea instance: %s\n", serverURL)
|
fmt.Printf("1. Go to your Gitea instance: %s\n", serverURL)
|
||||||
fmt.Println("2. Sign in and go to Settings > Applications")
|
fmt.Println("2. Sign in and go to Settings > Applications")
|
||||||
@ -415,8 +415,6 @@ func createLoginFromToken(name, serverURL string, token *oauth2.Token, insecure
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RefreshAccessToken manually renews an expired access token using the refresh token
|
// RefreshAccessToken manually renews an expired access token using the refresh token
|
||||||
// Note: In most cases, tokens are automatically refreshed when using login.Client()
|
|
||||||
// This function is primarily used for manual refreshes via CLI command
|
|
||||||
func RefreshAccessToken(login *config.Login) error {
|
func RefreshAccessToken(login *config.Login) error {
|
||||||
if login.RefreshToken == "" {
|
if login.RefreshToken == "" {
|
||||||
return fmt.Errorf("no refresh token available")
|
return fmt.Errorf("no refresh token available")
|
||||||
@ -425,12 +423,9 @@ func RefreshAccessToken(login *config.Login) error {
|
|||||||
// Check if token actually needs refreshing
|
// Check if token actually needs refreshing
|
||||||
if login.TokenExpiry > 0 && time.Now().Unix() < login.TokenExpiry {
|
if login.TokenExpiry > 0 && time.Now().Unix() < login.TokenExpiry {
|
||||||
// Token is still valid, no need to refresh
|
// Token is still valid, no need to refresh
|
||||||
fmt.Println("Token is still valid, no need to refresh.")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Access token expired, refreshing...")
|
|
||||||
|
|
||||||
// Create an expired Token object
|
// Create an expired Token object
|
||||||
expiredToken := &oauth2.Token{
|
expiredToken := &oauth2.Token{
|
||||||
AccessToken: login.Token,
|
AccessToken: login.Token,
|
||||||
|
Reference in New Issue
Block a user