Estimating the Discount Rate
As indicated in the comments, you would use the CAPM (or another equity factor model) to model stock returns $r_{it}$ beyond the risk-free rate $r_f$ as a function of returns on a market index $r_{Mt}$:
$$ r_{it} - r_f = \alpha_i + \beta_i (r_{Mt} - r_f) + \epsilon_{it}. $$
Once we have estimates $\hat\alpha_i$ and $\hat\beta_i$, we can use the average market index return $\bar{r}_M$ to estimate the expected return of asset $i$:
$$ \hat{r}_i - r_f = \hat\alpha_i + \hat\beta_i (\bar{r}_M - r_f),~\text{or} \\
\hat{r}_i = r_f + \hat\alpha_i + \hat\beta_i (\bar{r}_M - r_f). $$
Whither Alpha?
The decision about whether or not to use $\hat\alpha_i$ in the above can lead to debate. Some people will treat $\hat\alpha_i$ as correcting for trends and so will set $\hat\alpha_i=0$.
Others want to allow for the possibility that asset $i$ has some non-risk-factor related return. (Perhaps the firm has a unique patent or product.) In that case, including $\hat\alpha_i$ discounts cashflows further -- which makes us less happy when such a firm pays us dividends instead of reinvesting the money.)
You can read a bit more about dividend reinvestment policy here.
Why Use a Model?
Why not just measure the average stock return? That is typically too noisy. Using a model gives less noisy estimates, lets us correct for trends we do not know will continue (setting $\hat\alpha_i=0$), and ensures our pricing is tied to risk factors (or proxies for risk factors). The last part is important; we don't want a model that says we can get returns beyond $r_f$ for taking no risk.
Why Discount at This Rate?
We discount dividends at this rate for many reasons. First, riskier cashflows need to be discounted at a higher rate than $r_f$ to account for their risk. Second, the rate we use is because of opportunity cost: If the firm pays dividends, the value of those cashflows should be discounted to account for the opportunity cost of keeping the cash in the firm. Had we kept the cash in the firm, it would have grown at a rate $\hat{r}_i$. Therefore, that is the appropriate discount rate.
Discounting Dividends
Once we have an estimate of $\hat{r}_i$, we then use that to discount dividends paid to shareholders, possibly accounting for dividends growing at some rate $g$.
Typically, we assume equilibrium and so we pull things out of the single-period model and into a perpetuity form. This is not perfect, but multi-stage models tend to be hard to estimate since you also need to decide when transitions between stages occur.
If we characterize the futures dividends by the expected dividend in a year, we will value the equity as:
$$P_0 = \frac{E(D_1)}{\hat{r}_i},~\text{or} \\
P_0 = \frac{E(D_1)}{\hat{r}_i-g}$$
if dividends grow at rate $g$.
Timing of Dividends
Many firms do not pay dividends annually. However, doing all of the accounting for that here would be messy. I'll just say that we need to account for the time to the next dividend and payouts that may not be annual.
Uncertainty of Estimation
There is one problem (and now we are going beyond what you asked): our estimates of $\hat{r}_i$ are uncertain. There is uncertainty in the estimate $\bar{r}_M$ of average market index returns; and, there is uncertainty in the estimates $\hat\alpha_i$ and $\hat\beta_i$. There might even be uncertainty if we have to estimate the dividend growth rate $\hat{g}$.
In these cases, we need to consider the variance of our estimates $\sigma^2_{\hat{r}_i}={\rm var}(\hat{r}_i)$ and $\sigma^2_{\hat{g}}={\rm var}(\hat{g})$.
Since $\hat{r}_i$ and $\hat{g}$ appear in the denominator, the uncertainty does not cancel out as to whether we under- or over-estimated. Consider if dividends were \$10 annually and our discount rate were estimated at 10%. Then we would price the stock at $\frac{\\\$10}{0.1}=$\$100. However, if we were off by 1% in one way or the other, the stock might be valued at $\frac{\\\$10}{0.09}=$\$111.11 or $\frac{\\\$10}{0.11}=$\$90.91 -- so \$11.11 higher or \$9.19 lower.
The discount rate being lower has a larger effect than the discount rate being higher. Therefore, uncertainty about our discount rate means we need to adjust our valuation higher. You can do this by simulation or there is a closed-form solution. That is a bit complicated, but Chapter 13 in A Quantitative Primer on Investments with $R$ covers that and all of the above issues as well.