-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathauthentication.go
More file actions
53 lines (43 loc) · 1.12 KB
/
authentication.go
File metadata and controls
53 lines (43 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// test authentication, just using a command line call
// ex: ./authentication http://192.168.13.111:8080 openrmfprosrc hvs.xxxxxxxxxxxxxx
package main
import (
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"strings"
)
func main() {
apiPath := os.Args[1] + "/api/external/testauthentication"
apiKey := os.Args[2]
// Create a Bearer string by appending string access token
var bearer = "Bearer " + os.Args[3]
data := url.Values{}
data.Set("applicationKey", apiKey)
// create request
req, err := http.NewRequest("POST", apiPath, strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
// add authorization header to the req
req.Header.Add("Authorization", bearer)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
// send request with headers
client := &http.Client{}
resp, err := client.Do(req)
// //Handle Error
if err != nil {
log.Fatalf("An Error Occured %v", err)
}
defer resp.Body.Close()
//Read the response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
sb := string(body)
log.Printf(sb)
}