コード例 #1
0
 public static async Task SaveToken(FileDataStore datastore, string userid, UserNameToken token, CancellationToken cancellation)
 {
     cancellation.ThrowIfCancellationRequested();
     if (datastore != null)
     {
         await datastore.StoreAsync <UserNameToken>(userid, token);
     }
 }
コード例 #2
0
 private static async void SaveRefreshToken(UserNameToken AppToken, FileDataStore datastore, string userid)
 {
     if (AppToken != null)
     {
         UserNameToken settings = AppToken;
         await SaveToken(datastore, userid, settings, CancellationToken.None);
     }
 }
コード例 #3
0
        void VideoStartup(Model model)
        {
            player = new HostedPlayer();
            var res = model.encoderResolution;

            videoBuff = new VideoBuffer(res.width, res.height);
            player.SetVideoBuffer(videoBuff);

            var           account = AccountManager.Instance.CurrentAccount;
            UserNameToken utoken  = null;

            if (!account.IsAnonymous)
            {
                utoken = new UserNameToken(account.Name, account.Password);
            }

            if (model.metadataReceiver != null)
            {
                player.SetMetadataReciever(model.metadataReceiver);
            }

            MediaStreamInfo.Transport transp;
            switch (model.streamSetup.transport.protocol)
            {
            case TransportProtocol.http:
                transp = MediaStreamInfo.Transport.Http;
                break;

            case TransportProtocol.rtsp:
                transp = MediaStreamInfo.Transport.Tcp;
                break;

            default:
                transp = MediaStreamInfo.Transport.Udp;
                break;
            }
            MediaStreamInfo mstrInfo = new MediaStreamInfo(model.mediaUri.uri, transp, utoken);

            disposables.Add(player.Play(mstrInfo, this));
            InitPlayback(videoBuff);
        }
コード例 #4
0
        void VideoStartup(IVideoInfo iVideo)
        {
            playerEngine = new HostedPlayer();

            var           account = AccountManager.Instance.CurrentAccount;
            UserNameToken usToken = null;

            if (!account.IsAnonymous)
            {
                usToken = new UserNameToken(account.Name, account.Password);
            }
            playerEngine.SetMetadataReciever(new MetadataFramer((stream) => {
                using (Disposable.Create(() => stream.Dispose())) {
                    var xml = new XmlDocument();
                    try {
                        xml.Load(stream);
                        if (xml.DocumentElement != null && xml.DocumentElement.HasChildNodes)
                        {
                            //TODO: possible incorrect behaviour when multiple instances of odm are running
                            if (AppDefaults.visualSettings.EventsCollect_IsEnabled)
                            {
                                try {
                                    using (var sw = AppDefaults.MetadataFileInfo.AppendText()) {
                                        using (var xw = XmlWriter.Create(sw, new XmlWriterSettings()
                                        {
                                            Indent = true, CloseOutput = false
                                        })) {
                                            xml.DocumentElement.WriteTo(xw);
                                        }
                                        sw.WriteLine();
                                        sw.WriteLine("<!--------------------------------------------------------------------------------!>");
                                    }
                                } catch {
                                    //swallow error
                                }
                            }

                            MetadataReceived(xml);
                        }
                    } catch (Exception err) {
                        //TODO: possible incorrect behaviour when multiple instances of odm are running
                        if (AppDefaults.visualSettings.EventsCollect_IsEnabled)
                        {
                            try {
                                using (var sw = AppDefaults.MetadataFileInfo.AppendText()) {
                                    sw.WriteLine("<!---------------------------------------------------------------------------------");
                                    sw.WriteLine("ERROR: {0}", err.Message);
                                    sw.WriteLine("---------------------------------------------------------------------------------!>");
                                }
                            } catch {
                                //swallow error
                                dbg.Error(err);
                            }
                        }

                        dbg.Error(err);
                    }
                }
            }));
            var vs = AppDefaults.visualSettings;

            MediaStreamInfo.Transport medtranp = MediaStreamInfo.Transport.Tcp;
            switch (vs.Transport_Type)
            {
            case TransportProtocol.http:
                medtranp = MediaStreamInfo.Transport.Http;
                break;

            case TransportProtocol.rtsp:
                medtranp = MediaStreamInfo.Transport.Tcp;
                break;

            case TransportProtocol.tcp:
                medtranp = MediaStreamInfo.Transport.Tcp;
                break;

            case TransportProtocol.udp:
                medtranp = MediaStreamInfo.Transport.Udp;
                break;
            }

            MediaStreamInfo mstreamInfo = new MediaStreamInfo(iVideo.MediaUri, medtranp, usToken);

            playerEngine.Play(mstreamInfo, this);

            disposables.Add(playerEngine);
        }
コード例 #5
0
 public UserNameTokenToken(UserNameToken token)
 {
     UsernameToken = token;
 }
コード例 #6
0
        /// <summary>
        /// Oauth 2.0을 사용하여 유저 정보를 가져온다.
        /// </summary>
        /// <param name="clientId">Developer console에서 발급받은 userid</param>
        /// <param name="clientSecret">Developer console에서 발급받은 보안 번호</param>
        /// <param name="userName">사용자를 구별하기 위한 유저 이름 (닉네임)</param>
        /// <returns></returns>
        public async void CloudLogin()
        {
            string starturi  = null;
            string enduri    = null;
            string tokenuri  = null;
            string granttype = null;
            string drive     = null;

            if (option == LoginOption.GoogleDrive)
            {
                starturi  = UriCollection.GoogleAuthorizationUrl;
                enduri    = UriCollection.GoogleinstalledAppRedirectUri;
                tokenuri  = UriCollection.GoogleTokenUri;
                userName += "Google";
                granttype = "refresh_token";
                drive     = "Google";
            }
            else if (option == LoginOption.OneDrive)
            {
                starturi  = UriCollection.OneDriveAuthorizationUri;
                enduri    = UriCollection.OneDriveinstalledAppRedirectUri;
                tokenuri  = UriCollection.OneDriveTokenUri;
                userName += "OneDrive";
                granttype = "refresh_token";
                drive     = "OneDrive";
            }
            else
            {
                starturi  = UriCollection.DropBoxAuthorizationUri;
                tokenuri  = UriCollection.DropBoxTokenUri;
                userName += "DropBox";
                granttype = "authorization_code";
                drive     = "DropBox";
            }
            try
            {
                FileDataStore datastore       = new FileDataStore(path);
                UserNameToken oldRefreshToken = await LoadToken(datastore, userName, CancellationToken.None).ConfigureAwait(false);

                UserNameToken unametoken = new UserNameToken();
                TokenResult   appToken   = null;
                if (oldRefreshToken != null)
                {
                    if (oldRefreshToken.Token.refresh_token != null)
                    {
                        appToken = await WebAuthorization.RedeemAuthorizationCodeAsync(clientId, enduri, clientSecret, oldRefreshToken.Token.refresh_token, tokenuri, granttype, WebAuthorization.TokenOption.REFRESHTOKEN);

                        if (option == LoginOption.GoogleDrive)
                        {
                            appToken.refresh_token = oldRefreshToken.Token.refresh_token;
                        }
                        appToken.Drive = drive;
                    }
                    else
                    {
                        appToken = oldRefreshToken.Token;
                    }
                }
                // 신규 유저 접근 권한을 받아오거나 혹은 저장되어 있는 (기본 위치 C:\Users\bit-user\AppData\Roaming\)에 토큰을 가지고 유저정보를 가져온다.
                if (appToken == null)
                {
                    if (code != null)
                    {
                        appToken = await WebAuthorization.RedeemAuthorizationCodeAsync(clientId, enduri, clientSecret, code, tokenuri, "authorization_code", WebAuthorization.TokenOption.CODE);

                        appToken.Drive = drive;
                    }
                }
                if (appToken != null)
                {
                    if (appToken.Drive == "Google")
                    {
                        var result = await HttpHelper.RequstHttp("GET", "https://www.googleapis.com/drive/v2/about", null, appToken.access_token);

                        Dictionary <string, object> drivetext = HttpHelper.DerealizeJson(result.GetResponseStream());
                        var map = new ApiDataMapping();
                        map.Add("name", "DisplayName");
                        map.Add("quotaBytesTotal", "TotalSize", typeof(long));
                        map.Add("quotaBytesUsed", "UseSize", typeof(long));
                        map.Add("quotaBytesUsedAggregate", "EmptySize", typeof(long));
                        map.Add("quotaBytesUsedInTrash", "DeleteSize", typeof(long));
                        map.Add("quotaType", "DriveType");
                        map.Add("rootFolderId", "DriveID");
                        Dictionary <string, object> di = (Dictionary <string, object>)drivetext["user"];
                        driveinfo        = new DriveInfo(drivetext, map);
                        driveinfo.UserID = di["emailAddress"].ToString();
                        driveinfo.Status = "normal";
                        driveinfo.token  = appToken;
                    }
                    else if (appToken.Drive == "OneDrive")
                    {
                        var result = await HttpHelper.RequstHttp("GET", "https://api.onedrive.com/v1.0/drive", null, appToken.access_token);

                        Dictionary <string, object> drivetext = HttpHelper.DerealizeJson(result.GetResponseStream());
                        Dictionary <string, object> owner     = (Dictionary <string, object>)drivetext["owner"];
                        Dictionary <string, object> user      = (Dictionary <string, object>)owner["user"];
                        Dictionary <string, object> quoat     = (Dictionary <string, object>)drivetext["quota"];
                        var map = new ApiDataMapping();
                        map.Add("id", "DriveID", typeof(string));
                        map.Add("driveType", "DriveType");
                        driveinfo             = new DriveInfo(drivetext, map);
                        driveinfo.DisplayName = user["displayName"].ToString();
                        driveinfo.UserID      = user["id"].ToString();
                        driveinfo.TotalSize   = long.Parse(quoat["total"].ToString());
                        driveinfo.EmptySize   = long.Parse(quoat["remaining"].ToString());
                        driveinfo.UseSize     = long.Parse(quoat["used"].ToString());
                        driveinfo.DeleteSize  = long.Parse(quoat["deleted"].ToString());
                        driveinfo.Status      = quoat["state"].ToString();
                        driveinfo.token       = appToken;
                    }
                    else if (appToken.Drive == "DropBox")
                    {
                        var result = await HttpHelper.RequstHttp("GET", "https://api.dropbox.com/1/account/info", null, appToken.access_token);

                        Dictionary <string, object> drivetext = HttpHelper.DerealizeJson(result.GetResponseStream());
                        Dictionary <string, object> quato     = (Dictionary <string, object>)drivetext["quota_info"];
                        var map = new ApiDataMapping();
                        map.Add("uid", "UserId", typeof(string));
                        map.Add("display_name", "DisplayName");
                        driveinfo           = new DriveInfo(drivetext, map);
                        driveinfo.TotalSize = long.Parse(quato["quota"].ToString());
                        driveinfo.UseSize   = long.Parse(quato["normal"].ToString());
                        driveinfo.EmptySize = driveinfo.TotalSize - driveinfo.UseSize;
                        driveinfo.token     = appToken;
                        driveinfo.Status    = "normal";
                    }
                    appToken.uid        = driveinfo.UserID;
                    unametoken.UserName = this.userName;
                    unametoken.Token    = appToken;
                    SaveRefreshToken(unametoken, datastore, userName);
                    token = appToken;
                }
            }
            catch (Exception ex)
            {
            }
            this.OnComplete(this);
            this.Stop();
        }
コード例 #7
0
 protected override string AuthenticateToken(UserNameToken token)
 {
     return(token.UserName);
 }