Integration with MSAL(Azure AD) and GoLang: undefined

Issue

I’m integrating my Go Gin app with Azure AD for the company, ref: https://github.com/AzureAD/microsoft-authentication-library-for-go , however, it failed in the beginning step.

I got "undefined: publicClientApp"in this line:

publicClientapp, err := public.New("client_id", public.WithAuthority("https://login.microsoftonline.com/Enter_The_Tenant_Name_Here"))

Does anyone know why this happens?
Are there any successful examples for Go and AAD?

The official example is not clear and there are so many errors which quite confused me.
Thanks!

Solution

This seems to work just fine.

package main

import (
    "fmt"

    "github.com/AzureAD/microsoft-authentication-library-for-go/apps/public"
)

func main() {
    publicClientApp, err := public.New("client_id", public.WithAuthority("https://login.microsoftonline.com/Enter_The_Tenant_Name_Here"))
    if err != nil {
        panic(err)
    }
    fmt.Println(publicClientApp)
}

https://go.dev/play/p/WERsd46004p

You show the error message "undefined: publicClientApp" but you are declaring the client as publicClientapp. If you attempt to use publicClientApp afterwards, you will see that error, as it has not been defined. (Note the uppercase A).

Answered By – The Fool

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.