Exemplo n.º 1
0
        ///// <summary>Returns the contents of the ScopesByApiDict in to a single hashset.</summary>
        //public HashSet<string> ScopesDictToHash()
        //{
        //    HashSet<string> scopesHash = new HashSet<string>();

        //    foreach (string key in scopesByApiDict.Keys)
        //    {
        //        foreach (ScopeInfo scopeInfo in scopesByApiDict[key])
        //        {
        //            scopesHash.Add(scopeInfo.scope);
        //        }
        //    }

        //    return scopesHash;
        //}

        #endregion

        #region Api Calls

        /// <summary>Return a list of scopes with both their scope and description.</summary>
        public List <ScopeInfo> GetScopesForAPI(string api, string version, out string description, bool?readOnly = null)
        {
            Data.RestDescription restDescription = apis.RestData(api, version);

            var scopesDict = (Dictionary <string, Data.RestDescription.AuthData.Oauth2Data.ScopesDataElement>)restDescription.Auth.Oauth2.Scopes;

            var scopesList = new List <ScopeInfo>();

            foreach (string key in scopesDict.Keys)
            {
                scopesList.Add(new ScopeInfo()
                {
                    scope = key, description = scopesDict[key].Description
                });
            }

            description = restDescription.Description;

            return(scopesList);
        }
Exemplo n.º 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);
            }
        }