Beispiel #1
0
        public async Task <IActionResult> OAuth([FromBody] PlexOAuthViewModel wizard)
        {
            //https://app.plex.tv/auth#?forwardUrl=http://google.com/&clientID=Ombi-Test&context%5Bdevice%5D%5Bproduct%5D=Ombi%20SSO&pinID=798798&code=4lgfd
            // Plex OAuth
            // Redirect them to Plex

            Uri url;

            if (!wizard.Wizard)
            {
                url = await _plexOAuthManager.GetOAuthUrl(wizard.Pin.code);
            }
            else
            {
                var websiteAddress = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";
                url = await _plexOAuthManager.GetWizardOAuthUrl(wizard.Pin.code, websiteAddress);
            }

            if (url == null)
            {
                return(new JsonResult(new
                {
                    error = "Application URL has not been set"
                }));
            }

            return(new JsonResult(new { url = url.ToString() }));
        }
Beispiel #2
0
        public async Task <IActionResult> GetToken([FromBody] UserAuthModel model)
        {
            if (!model.UsePlexOAuth)
            {
                var user = await _userManager.FindByNameAsync(model.Username);

                if (user == null)
                {
                    // Could this be an email login?
                    user = await _userManager.FindByEmailAsync(model.Username);

                    if (user == null)
                    {
                        _log.LogWarning(string.Format("Failed login attempt by IP: {0}", GetRequestIP()));
                        return(new UnauthorizedResult());
                    }

                    user.EmailLogin = true;
                }


                // Verify Password
                if (await _userManager.CheckPasswordAsync(user, model.Password))
                {
                    return(await CreateToken(model.RememberMe, user));
                }
            }
            else
            {
                // Plex OAuth
                // Redirect them to Plex

                var websiteAddress = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";
                //https://app.plex.tv/auth#?forwardUrl=http://google.com/&clientID=Ombi-Test&context%5Bdevice%5D%5Bproduct%5D=Ombi%20SSO&pinID=798798&code=4lgfd
                var url = await _plexOAuthManager.GetOAuthUrl(model.PlexTvPin.code, websiteAddress);

                if (url == null)
                {
                    return(new JsonResult(new
                    {
                        error = "Application URL has not been set"
                    }));
                }
                return(new JsonResult(new { url = url.ToString(), pinId = model.PlexTvPin.id }));
            }

            _log.LogWarning(string.Format("Failed login attempt by IP: {0}", GetRequestIP()));
            return(new UnauthorizedResult());
        }