azure ad cli
https://teamsmiley.gitbook.io/devops/azure/active-directory
์ฌ๊ธฐ์ ์ด์ด์ ๋ง๋ ๋ค
๊ธฐ์กด cli๋ฅผ ์ฌ์ฉํ๋ค. https://teamsmiley.gitbook.io/devops/go-lang/create-cli
ํ ํฐ ๋ฐ์์ค๊ธฐ
package httpApi
import (
"context"
"log"
msal "github.com/AzureAD/microsoft-authentication-library-for-go/apps/confidential"
"github.com/spf13/viper"
)
const scope = "api://xxxxx/.default"
const clientID = "xxxxx"
func getSecret() string {
sec := viper.GetString("AZURE_SECRET")
if sec == "" {
log.Fatalf("AZURE_SECRET is missing, please configure it myctl configure --secret <secret>")
}
return sec
}
type tokenProvider struct{}
func (t *tokenProvider) OAuthToken() string {
clientCredential, err := msal.NewCredFromSecret(getSecret())
if err != nil {
log.Fatalf("Couldn't create client app (%s)", err)
}
app, err := msal.New(clientID, clientCredential, func(o *msal.Options) {
o.Authority = "https://login.microsoftonline.com/xxxxxxx"
})
if err != nil {
log.Fatalf("Couldn't get application (%s)", err)
}
ctx := context.Background()
token, err := app.AcquireTokenByCredential(ctx, []string{
scope,
})
if err != nil {
log.Fatalf("Error getting token (%s)", err)
}
return token.AccessToken
}xxxx๋ ๋ถ๋ถ์ ์ ๋ถ ์์ ํด์ค๋ค.
์ด์ http ๋ฆฌํ์คํธ๋ฅผ ๋ณด๋ด๊ธฐ ์ ์ ํธ์ถํด์ ํ ํฐ์ ๋ง๋ ํ ํ ํฐ์ http ๋ฆฌํ์คํธ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
์ด์ myctl์ ์ฌ์ฉํ๋ฉด ์ธ์ ๋ ํ ํฐ์ ๋ฐ์์์ ๊ทธ ํ ํฐ์ ์ด์ฉํ์ฌ api์ ์์ฒญํ ์ ์๋ค.
์ด๊ฑธ ์ฌ์ฉํ๋ฉด ์ด์ api์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์์๋ ์ธ์๋ ์๊ฒ ๋๋ค.
Last updated
Was this helpful?