-
-
Save michael-bey/908e75dca8158652016e5b517df71fdb to your computer and use it in GitHub Desktop.
Revisions
-
michael-bey revised this gist
Nov 16, 2017 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,8 +31,10 @@ func getToken(code string) { client_id := "fceae27c-cac4-4bd3-947e-xxxxxxx" //change to your APP-id scope := "offline_access%20people.read%20contacts.read.shared%20mail.read" //change to the permissions you need/want redirect_uri := "https%3A%2F%2Fxxx.xxx.xxx.xxx%2Fpermission" //change to match the Redirect URI you set in your app at apps.dev.microsoft.com client_secret := "encoded_pw_secret" //webapps now need a secret password, must be percent encoded postData := fmt.Sprintf("client_secret=%s&client_id=%s&scope=%s&code=%s&redirect_uri=%s&grant_type=authorization_code", client_secret, client_id, scope, code, redirect_uri) req, err := http.NewRequest("POST", "https://login.windows.net/common/oauth2/v2.0/token", strings.NewReader(postData)) if err != nil { @@ -55,5 +57,5 @@ func getToken(code string) { func main() { fmt.Println("starting") http.HandleFunc("/", requestHandler) http.ListenAndServeTLS(":443", "/etc/letsencrypt/live/your-cert.pem", "/etc/letsencrypt/live/yourprivkey.pem", nil) } -
staaldraad renamed this gist
Aug 2, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
staaldraad created this gist
Jul 7, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ package main import ( "crypto/tls" "fmt" "io/ioutil" "net/http" "net/url" "strings" ) func requestHandler(w http.ResponseWriter, req *http.Request) { u, err := url.Parse(req.RequestURI) if err != nil { panic(err) } m, _ := url.ParseQuery(u.RawQuery) fmt.Println(u.RawQuery) getToken(m["code"][0]) target := "https://outlook.office365.com/" //redirect the user so they think that everything was successful http.Redirect(w, req, target, http.StatusTemporaryRedirect) } func getToken(code string) { Transport := http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: false}, } client := http.Client{Transport: &Transport} client_id := "fceae27c-cac4-4bd3-947e-xxxxxxx" //change to your APP-id scope := "offline_access%20people.read%20contacts.read.shared%20mail.read" //change to the permissions you need/want redirect_uri := "https%3A%2F%2Fxxx.xxx.xxx.xxx%2Fpermission" //change to match the Redirect URI you set in your app at apps.dev.microsoft.com postData := fmt.Sprintf("client_id=%s&scope=%s&code=%s&redirect_uri=%s&grant_type=authorization_code", client_id, scope, code, redirect_uri) req, err := http.NewRequest("POST", "https://login.windows.net/common/oauth2/v2.0/token", strings.NewReader(postData)) if err != nil { return } req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return } fmt.Println(string(body)) } func main() { fmt.Println("starting") http.HandleFunc("/", requestHandler) http.ListenAndServeTLS(":443", "cert.pem", "key.pem", nil) }