In case you are using PnP-Powershell, and connecting to sharepoint online withou any special scopes, you can:
- provide appId & appSecret (needs to register an app in azure)
- provide a credential object:
$securepass = convertto-securestring $mypassword-asplaintext -force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential($user, $securepass )
- use stored credentials in you windows environment ( you will need to leverage of the Credential-manager module:
Install-Module -Name CredentialManager
Connect-PnPOnline -Url $SPSiteURL -Credentials $(Get-Credential -Credentials:[MyLabel])
In case you are using special scopes, like
Connect-PnPOnline -Url "$mysite" -Scopes @("Group.ReadWrite.All", "User.ReadWrite.All", "Directory.ReadWrite.All") -credentials $($my_cred)
It doesnt matter if you provide the credentials, you will be always prompted for a login. EDIT: You can apply this workaround, however, you will still need to use the scope command for certain scenarios, therefore, you will get a prompt. Sorry
- Removes the scopes
- Create / register an app in you azure and grant it any api permissions you may need.
- Generate a secret token for such appId
- Go to https://.sharepoint.com/_layouts/15/appinv.aspx
- Use the use the previous AppId in the lookupfield. Set domain to
localhost & redirect to http://localhost ( or any other value you may need ).
Fill up the "App's Permission Request XML" with the required permissions, some examples here:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>
or
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read"/>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/>
</AppPermissionRequests>