github.com/yaegashi/msgraph.go@v0.1.4/msauth/resource_owner_password_grant.go (about) 1 package msauth 2 3 import ( 4 "context" 5 6 "golang.org/x/oauth2" 7 "golang.org/x/oauth2/microsoft" 8 ) 9 10 // ResourceOwnerPasswordGrant preforms OAuth 2.0 client resource owner password grant and returns a token. 11 func (m *Manager) ResourceOwnerPasswordGrant(ctx context.Context, tenantID, clientID, clientSecret, username, password string, scopes []string) (oauth2.TokenSource, error) { 12 endpoint := microsoft.AzureADEndpoint(tenantID) 13 endpoint.AuthStyle = oauth2.AuthStyleInParams 14 config := &oauth2.Config{ 15 ClientID: clientID, 16 ClientSecret: clientSecret, 17 Endpoint: endpoint, 18 Scopes: scopes, 19 } 20 t, err := config.PasswordCredentialsToken(ctx, username, password) 21 if err != nil { 22 return nil, err 23 } 24 ts := config.TokenSource(ctx, t) 25 return ts, nil 26 }