J'ai un controller dans lequel j'initialise une variable de session "token"
Puis j'ai un "OAuthBearerAuthenticationProvider" dans lequel j'essai de lire la même variable session:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 public ActionResult Anonymous() { HttpContext.GetOwinContext().Set<string>("token", "toto"); Session["token"] = "testabc"; return View(); }
Même après que la méthode du controller ai été appelé, je n'arrive pas à lire le contenu de la variable de session (toujours null).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class OAuthBearerAuthenticationProvider : IOAuthBearerAuthenticationProvider { public Task ApplyChallenge(OAuthChallengeContext context) { context.Response.Redirect("/Account/Login"); return Task.FromResult<object>(null); } public Task RequestToken(OAuthRequestTokenContext context) { string token = string.Empty; //Marche pas!! token = context.OwinContext.Get<string>("token"); //Marche pas non plus!! if (HttpContext.Current != null && HttpContext.Current.Session != null) { token = HttpContext.Current.Session["token"] as string; } if (!string.IsNullOrEmpty(token)) { context.Token = token; } return Task.FromResult<object>(null); } public Task ValidateIdentity(OAuthValidateIdentityContext context) { return Task.FromResult<object>(null); } }
Le passage par "context.OwinContext.Get" ne fonctionne as non plus.
Pourquoi?
Comment passer mon token entre mon controller et OAuthBearerAuthenticationProvider ?
Voici ma configuration:
Merci pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public void Configuration(IAppBuilder app) { ConfigureAuth(app); } public partial class Startup { // Pour plus dinformations sur la configuration de lauthentification, rendez-vous sur http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { //// Read settings var issuer = WebConfigurationManager.AppSettings["TokenIssuer"]; var audience = WebConfigurationManager.AppSettings["TokenAudience"]; var key = WebConfigurationManager.AppSettings["TokenSigningKey"]; string token = string.Empty; // Add OAuth authentication var options = new JwtBearerAuthenticationOptions { AllowedAudiences = new[] { audience }, IssuerSecurityTokenProviders = new[] { new SymmetricKeyIssuerSecurityTokenProvider(issuer, key) }, Provider= new OAuthBearerAuthenticationProvider() }; app.UseJwtBearerAuthentication(options); } }
Partager