# 基础配置

我们将通过一个简单的 Demo 来阐述 CollectiveOAuth 类库的强大功能,在此之前,我们假设您已经:

  • 拥有 .NetFramework4.5及以上 开发环境以及相应 IDE
  • 熟悉 .Net MVC、WebApi
  • 熟悉 OAuth2授权流程

WebConfigappSettings标签下添加三方授权配置:

配置说明:

如果只用到单独的几个三方授权可以单独配置 也可以改造成其他方式存储,比如DB存储

<!--支付宝服务窗授权-->
<add key="CollectiveOAuth_ALIPAY_MP_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_ALIPAY_MP_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_ALIPAY_MP_Scope" value="auth_user" />
<add key="CollectiveOAuth_ALIPAY_MP_AlipayPublicKey" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_ALIPAY_MP_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=ALIPAY_MP" />

<!--微信服务号自动授权-->
<add key="CollectiveOAuth_WECHAT_MP_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_MP_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_MP_Scope" value="snsapi_userinfo" />
<add key="CollectiveOAuth_WECHAT_MP_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WECHAT_MP" />

<!-- 微信开放平台授权-->
<add key="CollectiveOAuth_WECHAT_OPEN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_OPEN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_OPEN_Scope" value="snsapi_login" />
<add key="CollectiveOAuth_WECHAT_OPEN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WECHAT_OPEN" />

<!--企业微信自动授权-->
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_AgentId" value="xxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_Scope" value="snsapi_userinfo" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WECHAT_ENTERPRISE" />

<!--企业微信扫码授权-->
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_SCAN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_SCAN_AgentId" value="xxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_SCAN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_WECHAT_ENTERPRISE_SCAN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WECHAT_ENTERPRISE_SCAN" />

<!--码云自动授权-->
<add key="CollectiveOAuth_GITEE_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITEE_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITEE_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=GITEE" />

<!--Github自动授权-->
<add key="CollectiveOAuth_GITHUB_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITHUB_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITHUB_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=GITHUB" />

<!--百度授权-->
<add key="CollectiveOAuth_BAIDU_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_BAIDU_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_BAIDU_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=BAIDU" />

<!--小米开放平台授权-->
<add key="CollectiveOAuth_XIAOMI_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_XIAOMI_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_XIAOMI_Scope" value="user/profile%20user/openIdV2%20user/phoneAndEmail" />
<add key="CollectiveOAuth_XIAOMI_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=XIAOMI" />

<!--钉钉开放平台授权-->
<add key="CollectiveOAuth_DINGTALK_SCAN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_DINGTALK_SCAN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_DINGTALK_SCAN_Scope" value="snsapi_login" />
<add key="CollectiveOAuth_DINGTALK_SCAN_RedirectUri" value="https://yours.domain.com/oauth2/DingTalkCallback" />

<!--OSChina授权-->
<add key="CollectiveOAuth_OSCHINA_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_OSCHINA_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_OSCHINA_Scope" value="snsapi_login" />
<add key="CollectiveOAuth_OSCHINA_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=OSCHINA" />

<!--Coding(扣钉)授权-->
<add key="CollectiveOAuth_CODING_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_CODING_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_CODING_Scope" value="user" />
<add key="CollectiveOAuth_CODING_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=CODING" />

<!--Linkin(领英)授权-->
<add key="CollectiveOAuth_LINKEDIN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_LINKEDIN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_LINKEDIN_Scope" value="r_liteprofile%20r_emailaddress%20w_member_social" />
<add key="CollectiveOAuth_LINKEDIN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=LINKEDIN" />

<!-- 微博授权-->
<add key="CollectiveOAuth_WEIBO_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_WEIBO_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_WEIBO_Scope" value="xxx" />
<add key="CollectiveOAuth_WEIBO_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WEIBO" />

<!-- QQ授权-->
<add key="CollectiveOAuth_QQ_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_QQ_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_QQ_UnionId" value="xxx" />
<add key="CollectiveOAuth_QQ_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=QQ" />

<!-- 微博授权-->
<add key="CollectiveOAuth_DOUYIN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_DOUYIN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_DOUYIN_Scope" value="user_info" />
<add key="CollectiveOAuth_DOUYIN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=DOUYIN" />

<!-- Google授权-->
<add key="CollectiveOAuth_GOOGLE_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_GOOGLE_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_GOOGLE_Scope" value="openid%20email%20profile" />
<add key="CollectiveOAuth_GOOGLE_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=GOOGLE" />

<!-- Facebook授权-->
<add key="CollectiveOAuth_FACEBOOK_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_FACEBOOK_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_FACEBOOK_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=FACEBOOK" />

<!-- 微软授权-->
<add key="CollectiveOAuth_MICROSOFT_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_MICROSOFT_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_MICROSOFT_Scope" value="user.read%20mail.read" />
<add key="CollectiveOAuth_MICROSOFT_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=MICROSOFT" />

<!-- 今日头条授权-->
<add key="CollectiveOAuth_TOUTIAO_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_TOUTIAO_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_TOUTIAO_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=TOUTIAO" />

<!-- Teambition授权-->
<add key="CollectiveOAuth_TEAMBITION_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_TEAMBITION_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_TEAMBITION_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=TEAMBITION" />

<!-- 人人网授权-->
<add key="CollectiveOAuth_RENREN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_RENREN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_RENREN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=RENREN" />

<!-- Pinterest授权-->
<add key="CollectiveOAuth_PINTEREST_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_PINTEREST_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_PINTEREST_Scope" value="read_public" />
<add key="CollectiveOAuth_PINTEREST_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=PINTEREST" />

<!-- StackOverflow授权-->
<add key="CollectiveOAuth_STACK_OVERFLOW_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_STACK_OVERFLOW_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_STACK_OVERFLOW_Scope" value="read_inbox" />
<add key="CollectiveOAuth_STACK_OVERFLOW_StackOverflowKey" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_STACK_OVERFLOW_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=STACK_OVERFLOW" />

<!-- 华为授权-->
<add key="CollectiveOAuth_HUAWEI_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_HUAWEI_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_HUAWEI_Scope" value="https%3A%2F%2Fwww.huawei.com%2Fauth%2Faccount%2Fbase.profile" />
<add key="CollectiveOAuth_HUAWEI_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=HUAWEI" />

<!-- 酷家乐授权-->
<add key="CollectiveOAuth_KUJIALE_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_KUJIALE_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_KUJIALE_Scope" value="get_user_info" />
<add key="CollectiveOAuth_KUJIALE_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=KUJIALE" />

<!-- Gitlab授权-->
<add key="CollectiveOAuth_GITLAB_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITLAB_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_GITLAB_Scope" value="read_user+openid+profile+email" />
<add key="CollectiveOAuth_GITLAB_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=GITLAB" />

<!-- 美团授权-->
<add key="CollectiveOAuth_MEITUAN_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_MEITUAN_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_MEITUAN_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=MEITUAN" />

<!-- 饿了么授权-->
<add key="CollectiveOAuth_ELEME_ClientId" value="xxxxxxxxxxxx" />
<add key="CollectiveOAuth_ELEME_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="CollectiveOAuth_KUJIALE_Scope" value="all" />
<add key="CollectiveOAuth_ELEME_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=ELEME" />

<!--自定义扩展授权-->
<add key="Extend_CollectiveOAuth_TEST_ClientId" value="xxxxxxxxxxxx" />
<add key="Extend_CollectiveOAuth_TEST_ClientSecret" value="xxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<add key="Extend_CollectiveOAuth_TEST_RedirectUri" value="https://yours.domain.com/oauth2/callback?authSource=WECHAT_MP" />