ADFS Auth
User credentials authentication

Struct

1
type AuthCnfg struct {
2
// SPSite or SPWeb URL, which is the context target for the API calls
3
SiteURL string `json:"siteUrl"`
4
Username string `json:"username"`
5
Password string `json:"password"`
6
// Following are not required for SPO
7
Domain string `json:"domain"`
8
RelyingParty string `json:"relyingParty"`
9
AdfsURL string `json:"adfsUrl"`
10
AdfsCookie string `json:"adfsCookie"`
11
}
Copied!
Gosip's ADFS also supports a scenario of ADFS or NTML behind WAP (Web Application Proxy) which adds additional auth flow and EdgeAccessCookie involved into play.

JSON

On-Premises configuration

private.json sample:
1
{
2
"siteUrl": "https://www.contoso.com/sites/test",
3
"username": "[email protected]",
4
"password": "this-is-not-a-real-password",
5
"relyingParty": "urn:sharepoint:www",
6
"adfsUrl": "https://login.contoso.com",
7
"adfsCookie": "FedAuth"
8
}
Copied!

On-Premises behing WAP configuration

private.json sample:
1
{
2
"siteUrl": "https://www.contoso.com/sites/test",
3
"username": "[email protected]",
4
"password": "this-is-not-a-real-password",
5
"relyingParty": "urn:AppProxy:com",
6
"adfsUrl": "https://login.contoso.com",
7
"adfsCookie": "EdgeAccessCookie"
8
}
Copied!

SharePoint Online configuration

private.json sample:
1
{
2
"siteUrl": "https://contoso.sharepoint.com/sites/test",
3
"username": "[email protected]",
4
"password": "this-is-not-a-real-password"
5
}
Copied!

Code sample

1
package main
2
3
import (
4
"log"
5
// "os"
6
7
"github.com/koltyakov/gosip"
8
strategy "github.com/koltyakov/gosip/auth/adfs"
9
)
10
11
func main() {
12
// authCnfg := &strategy.AuthCnfg{
13
// SiteURL: os.Getenv("SPAUTH_SITEURL"),
14
// Username: os.Getenv("SPAUTH_USERNAME"),
15
// Password: os.Getenv("SPAUTH_PASSWORD"),
16
// /* other auth props ...*/
17
// }
18
// or using `private.json` creds source
19
20
authCnfg := &strategy.AuthCnfg{}
21
configPath := "./config/private.json"
22
if err := authCnfg.ReadConfig(configPath); err != nil {
23
log.Fatalf("unable to get config: %v", err)
24
}
25
26
client := &gosip.SPClient{AuthCnfg: authCnfg}
27
// use client in raw requests or bind it with Fluent API ...
28
}
Copied!
Last modified 2yr ago
Export as PDF
Copy link