5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-09-19 21:32:31 +00:00
matterbridge/vendor/github.com/yaegashi/msgraph.go/msauth/resource_owner_password_grant.go

27 lines
767 B
Go

package msauth
import (
"context"
"golang.org/x/oauth2"
"golang.org/x/oauth2/microsoft"
)
// ResourceOwnerPasswordGrant preforms OAuth 2.0 client resource owner password grant and returns a token.
func (m *Manager) ResourceOwnerPasswordGrant(ctx context.Context, tenantID, clientID, clientSecret, username, password string, scopes []string) (oauth2.TokenSource, error) {
endpoint := microsoft.AzureADEndpoint(tenantID)
endpoint.AuthStyle = oauth2.AuthStyleInParams
config := &oauth2.Config{
ClientID: clientID,
ClientSecret: clientSecret,
Endpoint: endpoint,
Scopes: scopes,
}
t, err := config.PasswordCredentialsToken(ctx, username, password)
if err != nil {
return nil, err
}
ts := config.TokenSource(ctx, t)
return ts, nil
}