File tree Expand file tree Collapse file tree 4 files changed +12
-6
lines changed
Expand file tree Collapse file tree 4 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,9 @@ public class ClientFlowDto
44 {
55 public string Email { get ; set ; }
66 }
7+
8+ public class CodeFlowDto
9+ {
10+ public string ? Scope { get ; set ; }
11+ }
712}
Original file line number Diff line number Diff line change 11using DotNetCoreOAuth2 ;
22using MailKit ;
33using MailKit . Net . Imap ;
4- using MailKit . Search ;
54using MailKit . Security ;
65using Microsoft . AspNetCore . Mvc ;
76using Microsoft . Extensions . Options ;
87using Newtonsoft . Json ;
98using System . Text ;
10- using WebAppTest . Support ;
119
1210namespace WebAppTest . Controllers
1311{
Original file line number Diff line number Diff line change @@ -44,22 +44,24 @@ public IActionResult Index()
4444
4545 [ Route ( "code-flow" ) ]
4646 [ HttpPost ]
47- public async Task < IActionResult > CodeFlow ( )
47+ public async Task < IActionResult > CodeFlow ( CodeFlowDto dto )
4848 {
4949 OAuth2Client oAuth2Client = CreateOAuth2Client ( ) ;
5050
51+ var clientScope = dto ? . Scope ?? "openid email offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send" ;
52+
5153 var relativeUrl = Url . Action ( "GetToken" , "SampleIMAP" ) ! ;
5254 var redirectUrl = $ "{ Request . Scheme } ://{ Request . Host } { Request . PathBase } /{ relativeUrl . TrimStart ( '/' ) } ";
5355 var customState = Guid . NewGuid ( ) . ToString ( ) ;
5456 var codeChallengeUrl = await oAuth2Client . GenerateUrlForCodeFlowAsync (
55- "openid email offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send" ,
57+ clientScope ,
5658 redirectUrl ,
5759 new Dictionary < string , string > ( ) ,
5860 customState : customState ) ;
5961
6062 // In a real world, this will return a redirect to the code challenge url so that
6163 // the user will be immediately prompted with a login page.
62- var model = new ( ) ;
64+ var model = new SampleIMAPModel ( ) ;
6365 model . State = customState ;
6466 model . LoginLink = codeChallengeUrl . AbsoluteUri ;
6567 model . DebugLoginLink = DumpUrl ( model . LoginLink ) ;
Original file line number Diff line number Diff line change 3636
3737 <h2 >IMAP with code flow </h2 >
3838 <form action =" /sample-oauth2/code-flow" method =" post" >
39-
39+ <label for =" scop" >Scope : </label >
40+ <input style =" width : 800px " type =" text" id =" scope" name =" scope" value =" openid email offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send" />
4041 <input type =" submit" value =" Generate code flow link" />
4142 </form >
4243 }
You can’t perform that action at this time.
0 commit comments