mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-21 10:32:35 +01:00
2.8 KiB
2.8 KiB
msauth
Introduction
Very simple package to authorize applications against Microsoft identity platform.
It utilizes v2.0 endpoint so that it can authorize users using both personal (Microsoft) and organizational (Azure AD) account.
Usage
Device authorization grant
const (
= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
tenantID = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
clientID = "token_cache.json"
tokenCachePath )
var scopes = []string{"openid", "profile", "offline_access", "User.Read", "Files.Read"}
:= context.Background()
ctx := msauth.NewManager()
m .LoadFile(tokenCachePath)
m, err := m.DeviceAuthorizationGrant(ctx, tenantID, clientID, scopes, nil)
tsif err != nil {
.Fatal(err)
log}
.SaveFile(tokenCachePath)
m
:= oauth2.NewClient(ctx, ts)
httpClient ...
Client credentials grant
const (
= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
tenantID = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
clientID = "ZZZZZZZZZZZZZZZZZZZZZZZZ"
clientSecret )
var scopes = []string{msauth.DefaultMSGraphScope}
:= context.Background()
ctx := msauth.NewManager()
m , err := m.ClientCredentialsGrant(ctx, tenantID, clientID, clientSecret, scopes)
tsif err != nil {
.Fatal(err)
log}
:= oauth2.NewClient(ctx, ts)
httpClient ...
Resource owner password credentials grant
const (
= "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
tenantID = "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"
clientID = "ZZZZZZZZZZZZZZZZZZZZZZZZ"
clientSecret = "user.name@your-domain.com"
username = "secure-password"
password )
var scopes = []string{msauth.DefaultMSGraphScope}
:= context.Background()
ctx := msauth.NewManager()
m , err := m.ResourceOwnerPasswordGrant(ctx, tenantID, clientID, clientSecret, username, password, scopes)
tsif err != nil {
.Fatal(err)
log}
:= oauth2.NewClient(ctx, ts)
httpClient ...
Authorization code grant
- OAuth 2.0 authorization code grant flow
- Not yet implemented.