第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 REST API 在 Go 中向 Azure 進(jìn)行身份驗證

使用 REST API 在 Go 中向 Azure 進(jìn)行身份驗證

Go
精慕HU 2022-09-12 21:05:18
我正在嘗試使用戈朗向 Azure 服務(wù)管理/圖形 API 進(jìn)行身份驗證。使用純 REST 接口。無論我做什么,我總是以錯誤告終:{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.由于我沒有使用SDK,因此那里的樣本有限。任何幫助將不勝感激。package mainimport (    "bytes"    "encoding/json"    "io/ioutil"    "log"    "net/http")func main() {    authendpoint := "https://login.microsoftonline.com/8xxxxx7-6372-4bcb-xxx-xxxxxx/oauth2/token"    jsonData := []byte(`{        "resource":      "https://graph.microsoft.com",        "client_id":     "xxxxxxxx-7549-4ea2-b00d-xxxxxxxxxxx",        "client_secret": "Q.xxxxxxxxxxxxxx-6_CgA4yOi_8sS-",        "grant_type":    "client_credentials",        }`)    request, err := http.NewRequest("POST", authendpoint, bytes.NewBuffer(jsonData))    request.Header.Set("Content-Type", "application/json")    client := &http.Client{}    resp, err := client.Do(request)    if err != nil {        log.Fatal(err)    }    body, err := ioutil.ReadAll(resp.Body)    var res map[string]interface{}    json.NewDecoder(resp.Body).Decode(&res)    log.Println(string(body))}
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻(xiàn)1836條經(jīng)驗 獲得超5個贊

普拉文·普雷馬拉特內(nèi)發(fā)布的微軟請求文檔顯示,請求需要使用OAuth 2.0標(biāo)準(zhǔn)的要求進(jìn)行格式化。Content-Type: application/x-www-form-urlencoded

以下是微軟的文檔和示例:

https://docs.microsoft.com/en-us/graph/auth/auth-concepts#register-your-app-with-the-microsoft-identity-platform

POST /common/oauth2/v2.0/token HTTP/1.1

Host: https://login.microsoftonline.com

Content-Type: application/x-www-form-urlencoded


client_id=6731de76-14a6-49ae-97bc-6eba6914391e

&scope=user.read%20mail.read

&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...

&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F

&grant_type=authorization_code

&client_secret=JqQX2PNo9bpM0uEihUPzyrh  

以下是實現(xiàn)此目的的方法:


package main


import (

    "fmt"

    "net/http"

    "net/url"

    "strings"

)


func main() {

    authendpoint := "https://login.microsoftonline.com/8xxxxx7-6372-4bcb-xxx-xxxxxx/oauth2/token"

    body := url.Values(map[string][]string{

        "resource":      {"https://graph.microsoft.com"},

        "client_id":     {"xxxxxxxx-7549-4ea2-b00d-xxxxxxxxxxx"},

        "client_secret": {"Q.xxxxxxxxxxxxxx-6_CgA4yOi_8sS-"},

        "grant_type":    {"client_credentials"}})


    request, err := http.NewRequest(

        http.MethodPost,

        authendpoint,

        strings.NewReader(body.Encode()))

    if err != nil {

        panic(err)

    }


    request.Header.Set("Content-Type", "application/x-www-form-urlencoded")

    client := &http.Client{}

    resp, err := client.Do(request)

    if err != nil {

        panic(err)

    }

    fmt.Println(resp.StatusCode)

}


查看完整回答
反對 回復(fù) 2022-09-12
  • 1 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號