device

package
v0.0.0-...-8ec3e8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 11 Imported by: 0

README

Azure AD Device Auth Flow Sample

The sample shows Gosip custom auth with AAD Device Token Authorization.

Custom auth implementation

Checkout the code.

Azure App registration

1. Create or use existing app registration

2. Make sure that the app is configured to support device flow

  • Authentication settings
  • App permissions
    • Azure Service Management :: user_impersonation
    • SharePoint :: based on your application requirements
  • Manifest
    • oauth2AllowIdTokenImplicitFlow - true
    • oauth2AllowImplicitFlow - true
  • etc. based on application needs

Auth configuration and usage

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/koltyakov/gosip"
	"github.com/koltyakov/gosip/api"
	strategy "github.com/NoobD0gg/gosip-sandbox/strategies/device"
)

func main() {

	authCnfg := &strategy.AuthCnfg{
		SiteURL:  os.Getenv("SPAUTH_SITEURL"),
		ClientID: os.Getenv("SPAUTH_AAD_CLIENTID"),
		TenantID: os.Getenv("SPAUTH_AAD_TENANTID"),
	}

	client := &gosip.SPClient{AuthCnfg: authCnfg}
	sp := api.NewSP(client)

	res, err := sp.Web().Select("Title").Get()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Site title: %s\n", res.Data().Title)

}

Documentation

Overview

Package device implements AAD Device Auth Flow See more: https://docs.microsoft.com/en-us/azure/developer/go/azure-sdk-authorization#use-device-token-authentication Amongst supported platform versions are:

  • SharePoint Online + Azure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCnfg

type AuthCnfg struct {
	SiteURL  string `json:"siteUrl"`  // SPSite or SPWeb URL, which is the context target for the API calls
	ClientID string `json:"clientId"` // Azure AD App Registration Client ID
	TenantID string `json:"tenantId"` // Azure AD App Registration Tenant ID
}

AuthCnfg - AAD Device Flow auth config structure

Config sample:
{
  "siteUrl": "https://contoso.sharepoint.com/sites/test",
	"clientId": "61367a97-562c-4372-a9ee-b35307abdd26",
	"tenantId": "3f83fe32-29b2-488e-8c3f-c8b7a2e19a2f"
}

func (*AuthCnfg) CleanTokenCache

func (c *AuthCnfg) CleanTokenCache() error

CleanTokenCache removes token information

func (*AuthCnfg) GetAuth

func (c *AuthCnfg) GetAuth() (string, int64, error)

GetAuth authenticates, receives access token

func (*AuthCnfg) GetSiteURL

func (c *AuthCnfg) GetSiteURL() string

GetSiteURL gets SharePoint siteURL

func (*AuthCnfg) GetStrategy

func (c *AuthCnfg) GetStrategy() string

GetStrategy gets auth strategy name

func (*AuthCnfg) ParseConfig

func (c *AuthCnfg) ParseConfig(byteValue []byte) error

ParseConfig parses credentials from a provided JSON byte array content

func (*AuthCnfg) ReadConfig

func (c *AuthCnfg) ReadConfig(privateFile string) error

ReadConfig reads private config with auth options

func (*AuthCnfg) SetAuth

func (c *AuthCnfg) SetAuth(req *http.Request, httpClient *gosip.SPClient) error

SetAuth authenticates request noinspection GoUnusedParameter

func (*AuthCnfg) WriteConfig

func (c *AuthCnfg) WriteConfig(privateFile string) error

WriteConfig writes private config with auth options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL