コード例 #1
0
        internal virtual async Task <FileSystemResult> Login(Dictionary <string, object> authorization, string name, bool isUserAuth, bool scopescommaseparated)
        {
            if (!authorization.ContainsKey(ClientIdString) || !(authorization[ClientIdString] is string))
            {
                return(new FileSystemResult("Unable to find " + name + " '" + ClientIdString + "' in settings"));
            }
            ClientId = (string)authorization[ClientIdString];
            if (!authorization.ContainsKey(ClientSecretString) || !(authorization[ClientSecretString] is string))
            {
                return(new FileSystemResult("Unable to find " + name + " '" + ClientSecretString + "' in settings"));
            }
            ClientSecret = (string)authorization[ClientSecretString];
            if (!authorization.ContainsKey(RedirectUriString) || !(authorization[RedirectUriString] is string))
            {
                RedirectUri = DefaultRedirectUri;
            }
            else
            {
                RedirectUri = (string)authorization[RedirectUriString];
            }
            if (!authorization.ContainsKey(ScopesString) || !(authorization[ScopesString] is List <string>))
            {
                Scopes = DefaultScopes;
            }
            else
            {
                Scopes = (List <string>)authorization[ScopesString];
            }
            if (!authorization.ContainsKey(UserAgentString) || !(authorization[UserAgentString] is string))
            {
                UserAgent = "CloudFileSystem/1.0";
            }
            else
            {
                UserAgent = (string)authorization[UserAgentString];
            }
            if (isUserAuth)
            {
                FileSystemResult r = await FillFromUserAuth();

                return(r);
            }
            if (_provider == null)
            {
                return(new FileSystemResult <IFileSystem>("Cannot find valid Authorization Provider for " + name));
            }
            AuthRequest request = new AuthRequest {
                Name = name, LoginUrl = OAuthLoginUrl, ClientId = ClientId, Scopes = Scopes, RedirectUri = RedirectUri, ScopesCommaSeparated = scopescommaseparated
            };
            AuthResult result = await _provider.Login(request);

            if (result.HasError)
            {
                return(new FileSystemResult <IFileSystem>(result.ErrorString));
            }
            return(await FillFromLogin(result.Code));
        }