You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将自建OAuth2服务端点配置到Cortana OAuth2连接服务以获取令牌?

Got it, let's break down how to get your custom OAuth2 provider (built as an App Service) hooked up with Cortana Connected Services so you can fetch access tokens from Cortana apps. Here's what you need to know:

1. Verify Your Existing OAuth2 Provider Setup

First, make sure your OAuth2 authorization server (built following the reference example) is up and running. Confirm that core endpoints like the authorization endpoint and token endpoint are accessible and functioning correctly—this is critical for Cortana to communicate with your service.

2. Configure Cortana Connected Services with Your OAuth2 Endpoints

Next, you'll need to register your custom OAuth2 provider with Cortana Connected Services. You'll have to input key details like:

  • Your provider's authorization endpoint URL
  • Your provider's token endpoint URL
  • The client ID and client secret assigned to your Cortana app (ensure these match exactly what's configured in your OAuth2 provider)

This setup tells Cortana where to redirect users for authentication and how to request access tokens once authorization is granted.

Example Code for Cortana Authentication in Your Authorization Function

Here's a snippet of how you might handle the login flow in your authentication provider's authorization function, integrating Cortana-specific authentication logic:

public ActionResult Login() 
{ 
    var authentication = HttpContext.GetOwinContext().Authentication; 
    // Add your Cortana-specific authentication logic here
    // For example: Redirect to Cortana's authorization flow, or validate incoming Cortana auth requests
    if (/* Check if the request is coming from Cortana */)
    {
        // Trigger Cortana's authentication challenge
        authentication.Challenge("Cortana");
        return new HttpUnauthorizedResult();
    }
    // Add other authentication flows for non-Cortana requests as needed
    return View();
}

Key notes for this code:

  • Use HttpContext.GetOwinContext().Authentication to access the OWIN authentication pipeline
  • The Challenge method initiates the Cortana authentication flow (make sure "Cortana" is registered as an authentication middleware in your OWIN startup configuration)
  • Adjust the conditional check to detect when the request originates from a Cortana app, so you can route it through the correct authentication path

内容的提问来源于stack exchange,提问作者user2231

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:08:04