コード例 #1
0
        public SPOService InstantiateSPOService(Uri url, string loginUrl, PSCredential credentials,
                                                string authenticationUrl = COMMON_AUTH_URL, PromptBehavior?behavior = null)
        {
            if (!IsValidServerVersion(url))
            {
                throw new InvalidOperationException(StringResourceManager.GetResourceString(
                                                        "ValidateServerVersionInvalidVersion",
                                                        new object[0]));
            }
            var context = new CmdLetContext(url.ToString(), null, null); // this is where the site "sites/Clients" is set.

            if (credentials == null)
            {
                OAuthSession session;
                if (CTX.SP1 == null)
                {
                    session = new OAuthSession(authenticationUrl);
                    session.SignIn(loginUrl, behavior.Value);                      // the login Url is the base site though.
                }
                else
                {
                    CTX.SP1.OAuthSession.EnsureValidAuthToken();
                    session = CTX.SP1.OAuthSession;
                }

                context.OAuthSession = session;
            }
            else
            {
                var credentials2 = new SharePointOnlineCredentials(credentials.UserName, credentials.Password);
                context.Credentials = credentials2;
            }
            return(new SPOService(context));
        }
コード例 #2
0
        public SPOService SwitchContext(string newWebUrl, CmdLetContext currentContext)
        {
            if (!newWebUrl.EndsWith("/"))
            {
                newWebUrl = newWebUrl + "/";
            }

            OAuthSession oauth      = currentContext.OAuthSession;
            var          newContext = new CmdLetContext(newWebUrl, null, null);

            if (currentContext.Credentials == null)
            {
                newContext.OAuthSession = oauth;
                newContext.OAuthSession.EnsureValidAuthToken();
            }
            else
            {
                newContext.Credentials = currentContext.Credentials;
            }

            return(new SPOService(newContext));
        }