generated from mattermost/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathget_super_user_token.go
More file actions
35 lines (27 loc) · 909 Bytes
/
get_super_user_token.go
File metadata and controls
35 lines (27 loc) · 909 Bytes
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
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package msgraph
import (
"net/http"
"net/url"
"github.com/pkg/errors"
)
type AuthResponse struct {
TokenType string `json:"token_type"`
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
}
func (c *client) GetSuperuserToken() (string, error) {
u := EntraIDEndpoint(c.conf.OAuth2Authority, c.conf.OAuth2TenantType).TokenURL
res := AuthResponse{}
data := url.Values{}
data.Set("client_id", c.conf.OAuth2ClientID)
data.Set("scope", MSGraphEndpoint(c.conf.OAuth2TenantType)+"/.default")
data.Set("client_secret", c.conf.OAuth2ClientSecret)
data.Set("grant_type", "client_credentials")
_, err := c.CallFormPost(http.MethodPost, u, data, &res)
if err != nil {
return "", errors.Wrap(err, "msgraph GetSuperuserToken")
}
return res.AccessToken, nil
}