What youre asking is possible but it's a lot of work.
I had to setup an OAuth v2.0 process just using individual REST requests (rather than using the OAuth v2.0 setup functionality) and it was difficult.
If you want to set it up in either groovy or REST requests (which is easier) you'll need to identify all the individual requests that are exercised during the OAuth v2.0 process. Without this info people arent going to be able to help.
There are going to be at least 5 individual requests (i actually had 12) that youll need to identify before you can start trying to set this up.
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta