mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-30 05:35:44 +00:00 
			
		
		
		
	 a9e8bf89a9
			
		
	
	a9e8bf89a9
	
	
	
		
			
			* refactor: return all values from body in the providers * refactor: only accept claims following the OIDC spec * feat: map info from OIDC claims to headers * feat: add support for required oauth groups * fix: bot suggestions * feat: get claims from github and google * fix: close body correctly
		
			
				
	
	
		
			51 lines
		
	
	
		
			933 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			933 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package providers
 | |
| 
 | |
| import (
 | |
| 	"encoding/json"
 | |
| 	"io"
 | |
| 	"net/http"
 | |
| 	"tinyauth/internal/constants"
 | |
| 
 | |
| 	"github.com/rs/zerolog/log"
 | |
| )
 | |
| 
 | |
| func GetGenericUser(client *http.Client, url string) (constants.Claims, error) {
 | |
| 	// Create user struct
 | |
| 	var user constants.Claims
 | |
| 
 | |
| 	// Using the oauth client get the user info url
 | |
| 	res, err := client.Get(url)
 | |
| 
 | |
| 	// Check if there was an error
 | |
| 	if err != nil {
 | |
| 		return user, err
 | |
| 	}
 | |
| 
 | |
| 	defer res.Body.Close()
 | |
| 
 | |
| 	log.Debug().Msg("Got response from generic provider")
 | |
| 
 | |
| 	// Read the body of the response
 | |
| 	body, err := io.ReadAll(res.Body)
 | |
| 
 | |
| 	// Check if there was an error
 | |
| 	if err != nil {
 | |
| 		return user, err
 | |
| 	}
 | |
| 
 | |
| 	log.Debug().Msg("Read body from generic provider")
 | |
| 
 | |
| 	// Unmarshal the body into the user struct
 | |
| 	err = json.Unmarshal(body, &user)
 | |
| 
 | |
| 	// Check if there was an error
 | |
| 	if err != nil {
 | |
| 		return user, err
 | |
| 	}
 | |
| 
 | |
| 	log.Debug().Msg("Parsed user from generic provider")
 | |
| 
 | |
| 	// Return the user
 | |
| 	return user, nil
 | |
| }
 |