You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: oauth.go
    path of file: ./repos/portainer/api/oauth
    
    the code of the file until where you have to start completion: package oauth

import (
	"context"
	"io"
	"mime"
	"net/http"
	"net/url"
	"strings"

	portainer "github.com/portainer/portainer/api"

	"github.com/gola
    
func (*Service) Authenticate(code string, configuration *portainer.OAuthSettings) (string, error) {
	token, err := getOAuthToken(code, configuration)
	if err != nil {
		log.Debug().Err(err).Msg("failed retrieving oauth token")

		return "", err
	}

	idToken, err := getIdToken(token)
	if err != nil {
		log.Debug().Err(err).Msg("failed parsing id_token")
	}

	resource, err := getResource(token.AccessToken, configuration)
	if err != nil {
		log.Debug().Err(err).Msg("failed retrieving resource")

		return "", err
	}

	resource = mergeSecondIntoFirst(idToken, resource)

	username, err := getUsername(resource, configuration)
	if err != nil {
		log.Debug().Err(err).Msg("failed retrieving username")

		return "", err
	}

	return username, nil
}