예제 #1
0
        public AuthenticatedUserInfo ChooseScopesAndAuthenticate(string api, string version, ClientSecrets secrets)
        {
            var info = new AuthenticatedUserInfo()
            {
                apiNameAndVersion = api + ":" + version,
                scopes            = ChooseScopes(api, version)
            };

            string script = "Read-Host '\nYou will now authenticate for this API. Press any key to continue'";
            Collection <PSObject> results = invokablePSInstance.InvokeCommand.InvokeScript(script);

            //Now, authenticate.
            info = OAuth2Base.GetAuthTokenFlow(info, secrets, force: true);

            PrintPretty(string.Format("{0}:{1} has been authenticated and saved.", api, version), "green");

            return(info);
        }
예제 #2
0
        public AuthenticatedUserInfo AuthenticatePreChosenScopes(string api, string version, ClientSecrets secrets,
                                                                 ScopeSelectionTypes PreSelectScopes = ScopeSelectionTypes.None)
        {
            if (PreSelectScopes == ScopeSelectionTypes.None)
            {
                return(ChooseScopesAndAuthenticate(api, version, secrets));
            }
            else
            {
                Data.RestDescription restDescription = apis.RestData(api, version);

                HashSet <string> scopes = new HashSet <string>();

                switch (PreSelectScopes)
                {
                case ScopeSelectionTypes.ReadOnly:
                    scopes.UnionWith(restDescription.Auth.Oauth2.Scopes.Keys.Where(x => x.Contains("readonly")));
                    break;

                case ScopeSelectionTypes.ReadWrite:
                    scopes.UnionWith(restDescription.Auth.Oauth2.Scopes.Keys.Where(x => !x.Contains("readonly")));
                    break;

                default:
                    scopes.UnionWith(restDescription.Auth.Oauth2.Scopes.Keys);
                    break;
                }

                var authUserInfo = new AuthenticatedUserInfo()
                {
                    apiNameAndVersion = api + ":" + version,
                    scopes            = CheckForRequiredScope(scopes)
                };

                AuthenticatedUserInfo info = OAuth2Base.GetAuthTokenFlow(authUserInfo, secrets, force: true);

                return(info);
            }
        }