我有一个ASP.NET Web API,我在Azure Active Directory下注册了一个新的应用程序 .
这就是ConfigureAuth在Web API的源代码中的方式 .
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
OAuthOptions = new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = false,
TokenEndpointPath = new PathString("/Token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
Provider = new ApplicationOAuthProvider("self"),
AuthenticationType = "LocalBearer"
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}
另一方面,我有一个命令行应用程序,可以访问Web API并向它询问一些数据 .
从命令行我无法使用用户凭据登录(这是一项要求)所以我想生成一个可能在一两年内到期的个人访问令牌,并使用该个人访问令牌构建我的API调用 . 如果可能,那么我可以避免使用用户名/密码登录来生成令牌 .
这个场景有没有文档?如何为我的控制台应用程序生成个人访问令牌以连接到Azure中托管的Web API?