AddIn Only
AddIn Only authentication
This type of authentication uses AddIn Only policy and OAuth bearer tokens for authenticating HTTP requests.

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
// Client ID obtained when registering the AddIn
5
ClientID string `json:"clientId"`
6
// Client Secret obtained when registering the AddIn
7
ClientSecret string `json:"clientSecret"`
8
// Your SharePoint Online tenant ID (optional)
9
Realm string `json:"realm"`
10
}
Copied!
Realm can be left empty or filled in, that will add small performance improvement. The easiest way to find tenant is to open SharePoint Online site collection, click Site Settings -> Site App Permissions. Taking any random app, the tenant ID (realm) is the GUID part after the @.

JSON

private.json sample:
1
{
2
"siteUrl": "https://contoso.sharepoint.com/sites/test",
3
"clientId": "e2763c6d-7ee6-41d6-b15c-dd1f75f90b8f",
4
"clientSecret": "OqDSAAuBChzI+uOX0OUhXxiOYo1g6X7mjXCVA9mSF/0="
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/addin"
9
)
10
11
func main() {
12
// authCnfg := &strategy.AuthCnfg{
13
// SiteURL: os.Getenv("SPAUTH_SITEURL"),
14
// ClientID: os.Getenv("SPAUTH_CLIENTID"),
15
// ClientSecret: os.Getenv("SPAUTH_CLIENTSECRET"),
16
// }
17
// or using `private.json` creds source
18
19
authCnfg := &strategy.AuthCnfg{}
20
configPath := "./config/private.json"
21
if err := authCnfg.ReadConfig(configPath); err != nil {
22
log.Fatalf("unable to get config: %v", err)
23
}
24
25
client := &gosip.SPClient{AuthCnfg: authCnfg}
26
// use client in raw requests or bind it with Fluent API ...
27
}
Copied!
Last modified 1yr ago
Export as PDF
Copy link