"The president's comment to me was that, 'We put a six-month deadline out there. Let's work it out. If we can't get it worked out in six months, we'll give it some more time, but we've got to get this worked out legislatively,' " Lankford said outside a town hall here Thursday night.
Trump did not specify how long an extension might last, Lankford said.
"He wants a legislative solution," the senator said. "His focus was, 'We've got to get a legislative solution.' "
A Lankford spokesman, D.J. Jordan, said Trump made the comments during a phone call with the senator last month.
The White House did not immediately respond Thursday to a request for comment.
The president hinted at this possibility in a tweet Sept. 5, the day he announced that his administration would end an Obama-era program, known as Deferred Action for Childhood Arrivals, that allows these immigrants to stay in the country without fear of deportation.
Trump and Attorney General Jeff Sessions called the program an unconstitutional use of executive authority in the face of the threat of lawsuits from Texas and other states.
"Congress now has 6 months to legalize DACA," Trump wrote Sept. 5. "If they can't, I will revisit the issue!"
There are currently 690,000 young people with DACA status, according to the Department of Homeland Security.
Extending the program could potentially restart those legal threats and create an administrative headache at DHS, which last week stopped accepting any more renewal applications for DACA recipients.
House Democrats are seeking sufficient GOP support to force a vote on legislation known as the Dream Act that would provide permanent legal status to roughly 1.6 million dreamers.
So far, all House Democrats and one Republican have signed a document that would call for an up-or-down vote on the measure — far short of the majority of House lawmakers needed to bring up the legislation for consideration.
That effort fell into potential jeopardy after the Trump administration released a list of hard-line immigration demands late Sunday, including funding for a border wall, a crackdown on the influx of Central American minors and curbs on federal grants to "sanctuary cities."
Lankford, a conservative Republican, rose from the House to the Senate in 2014 after winning a special election to replace retiring Sen. Tom Coburn (R-Okla.).
On immigration, Lankford recently co-authored a conservative alternative to the Dream Act that offers young undocumented immigrants a 15-year path to citizenship.
"I think we'll be actually voting on something like this in January or February," he said.
The Succeed Act bars dreamers from taking advantage of existing laws that let legal immigrants petition authorities to allow foreign relatives come to the United States.
Sponsors of the bill have said this provision is meant to ensure that the parents of dreamers covered by the bill do not receive preferential treatment.
Lankford expressed sympathy for dreamers Thursday night, noting there are roughly 7,500 in Oklahoma.
"We've got to figure out what to do with these kids," he told an audience of about 200 people at the town hall.
"These are kids that have grown up here. I'm not interested in deporting them and kicking them out. But I'm also not interested in them ending up in a limbo status on this."
Lankford confirmed Trump's comments to him after describing them to several 20-somethings who approached him to talk about DACA after the town hall.
"I was trying to set them at ease and to say, 'This is going to get worked out. The president's even said to me, we're going to get this worked out and find a solution to this legislatively,' " he said.
Jordan Mazariegos, 24, a dreamer who is studying at accounting at Oklahoma State University, was not fully reassured.
"I don't know," he said after hearing the comments. "I'll believe it when I see it."
Ed O'Keefe, David Nakamura and Philip Rucker contributed to this report.