Malachi 3:17: "'They shall be mine, says the LORD of hosts, in the day when I make up my treasured possession, and I will spare them as a man spares his son who serves him.'"
John 10:27-30: "27 'My sheep hear my voice, and I know them, and they follow me. 28 I give them eternal life, and they will never perish, and no one will snatch them out of my hand. 29 My Father, who has given them to me, is greater than all, and no one is able to snatch them out of the Father's hand. 30 I and the Father are one.'"
John 6:39: "'And this is the will of him who sent me, that I should lose nothing of all that he has given me, but raise it up on the last day.'"
+++
The text is public domain:
Thine forever, God of love!Hear us from Thy throne above;Thine forever may we beHere and in eternity!Thine forever! Oh, how blestThey who find in Thee their rest!Savior, guardian, heav'nly friend,O defend us to the end!Thine forever, Lord of Life!Shield us through our earthly strife.Thou, the life, the truth, the way,Guide us to the realms of day.Thine forever! Shepherd, keepThese Thy frail and trembling sheep;Safe alone beneath Thy care,Let us all Thy goodness share.Thine forever! Thou our guide,All our wants by Thee supplied,All our sins by Thee forgiv'n;Lead us, Lord, from earth to heav'n.
+++
All three passages could be cited for the phrase "Thine forever" that appears at the beginning of each verse: "'They shall be mine'" in Malachi 3:17, "'who has given them to me'" in John 10:29, and "'all that he has given me'" in John 6:39. The verse from Malachi is probably the primary source though; it bears the closest resemblance, and the verses from John appear elsewhere in the hymn.
The sheep imagery from John 10:27-30 is in the fourth verse, and "'los[ing] nothing of all that he has given me'" in John 6:39 seems to be referred to in the lines "Guide us to the realms of day" at the end of the third verse and "Lead us, Lord, from earth to heav'n" at the end of the fifth.
+++
The lines "Oh, how blest [are] / They who find in Thee their rest!" in the second verse seem to refer to Matthew 11:28: "'Come to me, all who labor and are heavy laden, and I will give you rest.'"
The titles in the line "Thou, the life, the truth, the way" in the third verse come from John 14:6 ("Jesus said to him, 'I am the way, and the truth, and the life. No one comes to the Father except through me.'"), and the title "Shepherd" in the fourth verse could come from John 10:11, 14 ("'I am the good shepherd'" appears in both verses) or Psalm 23:1 ("The LORD is my shepherd; I shall not want.").
+++
The line "Let us all Thy goodness share" in the fourth verse could be understood two different ways, depending on what "all" modifies (either "us" or "Thy goodness"). It could mean either "Let all of us share Thy goodness" or "Let us share the entirety of Thy goodness."
+++
The phrase "Thine forever" is repeated at the beginning of each verse in a rhetorical effect called anaphora. Here, this repetition provides a sense of the constancy and duration of "forever."