ondemand

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: 13 Imported by: 0

README

On-Demand auth flow

During the development, it's common to face a situation when production-level auth (AddIn Onli, Azure AD application) can't be configured in the desired timeframes and no auth strategies work. A simple example might be 2FA (multi-factor authentication) or custom ADFS provider. As a quick workaround, the On-Demand auth can help.

On-Demand means that an interactive browser session is started where a user can provide the credentials as if he/she opens the SharePoint site and follows the same flow as reaching the site in a browser.

In that strategy, the application actually opens the browser and communicates via debug protocol for the auth cookies when uses them in the requests.

On-Demand auth is based on Lorca project, however, a vital part of the functionality is not exposed as a public API in Lorca, so the dependency is imported from a fork with only that small change in exposing one additional method.

Lorca masters Chrome Debug Protocol, therefore, the Chrome/Chromium browser must be installed in the system where On-Demand auth is intended to be called.

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/ondemand"
)

func main() {

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

	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 ondemand implements On-Demand Auth Flow Amongst supported platform versions are:

  • SharePoint Online
  • SharePoint On-Premises (cookie-based auths)

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
}

AuthCnfg - On-Demand auth config structure

Config sample:
{
  "siteUrl": "https://contoso.sharepoint.com/sites/test",
}

func (*AuthCnfg) CleanCookieCache

func (c *AuthCnfg) CleanCookieCache() error

CleanCookieCache removes cookie 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 ALL

func (*AuthCnfg) WriteConfig

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

WriteConfig writes private config with auth options

type Cookie struct {
	Domain  string  `json:"domain"`
	Name    string  `json:"name"`
	Value   string  `json:"value"`
	Expires float64 `json:"expires"`
}

Cookie struct

type Cookies

type Cookies []Cookie

Cookies type

Jump to

Keyboard shortcuts

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