Change Config Read Way
This commit is contained in:
parent
252d39b70c
commit
ce00fb88eb
23
outlook.go
23
outlook.go
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,9 +16,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cliid string
|
cliId string
|
||||||
rediuri string
|
redirectUri string
|
||||||
scope string
|
scope string
|
||||||
|
authUrl string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -27,9 +29,10 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
}
|
}
|
||||||
cliid = viper.GetString("client_id")
|
authUrl = viper.GetString("auth_url")
|
||||||
rediuri = viper.GetString("redirect_uri")
|
cliId = GetURLValue(authUrl, "client_id")
|
||||||
scope = viper.GetString("scope")
|
redirectUri, _ = url.QueryUnescape(GetURLValue(authUrl, "redirect_uri"))
|
||||||
|
scope, _ = url.QueryUnescape(GetURLValue(authUrl, "scope"))
|
||||||
//refreshtoken := "xxxx"
|
//refreshtoken := "xxxx"
|
||||||
//fmt.Println(MSGetUserInfo(MSGetToken(refreshtoken,"user.read mail.read")))
|
//fmt.Println(MSGetUserInfo(MSGetToken(refreshtoken,"user.read mail.read")))
|
||||||
//code := "xxx"
|
//code := "xxx"
|
||||||
@ -41,11 +44,11 @@ func MSFirGetToken(code string) (access string, refresh string) {
|
|||||||
var r http.Request
|
var r http.Request
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
r.Form.Add("client_id", cliid)
|
r.Form.Add("client_id", cliId)
|
||||||
r.Form.Add("grant_type", "authorization_code")
|
r.Form.Add("grant_type", "authorization_code")
|
||||||
r.Form.Add("scope", scope)
|
r.Form.Add("scope", scope)
|
||||||
r.Form.Add("code", code)
|
r.Form.Add("code", code)
|
||||||
r.Form.Add("redirect_uri", rediuri)
|
r.Form.Add("redirect_uri", redirectUri)
|
||||||
body := strings.NewReader(r.Form.Encode())
|
body := strings.NewReader(r.Form.Encode())
|
||||||
req, err := http.NewRequest("POST", MsApiUrl+"/common/oauth2/v2.0/token", body)
|
req, err := http.NewRequest("POST", MsApiUrl+"/common/oauth2/v2.0/token", body)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
@ -67,11 +70,11 @@ func MSGetToken(refreshtoken string) (access string) {
|
|||||||
var r http.Request
|
var r http.Request
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
r.Form.Add("client_id", cliid)
|
r.Form.Add("client_id", cliId)
|
||||||
r.Form.Add("grant_type", "refresh_token")
|
r.Form.Add("grant_type", "refresh_token")
|
||||||
r.Form.Add("scope", scope)
|
r.Form.Add("scope", scope)
|
||||||
r.Form.Add("refresh_token", refreshtoken)
|
r.Form.Add("refresh_token", refreshtoken)
|
||||||
r.Form.Add("redirect_uri", rediuri)
|
r.Form.Add("redirect_uri", redirectUri)
|
||||||
body := strings.NewReader(r.Form.Encode())
|
body := strings.NewReader(r.Form.Encode())
|
||||||
fmt.Println(body)
|
fmt.Println(body)
|
||||||
req, err := http.NewRequest("POST", MsApiUrl+"/common/oauth2/v2.0/token", body)
|
req, err := http.NewRequest("POST", MsApiUrl+"/common/oauth2/v2.0/token", body)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user