相关文章推荐
暴躁的石榴  ·  翻译 - Dolibarr ERP CRM ...·  1 月前    · 
不羁的饺子  ·  Debezium | Apache Flink·  1 月前    · 
讲道义的烈酒  ·  Debezium-JSON--流式计算 ...·  1 月前    · 
从容的大脸猫  ·  零代码第三方数据接入 | TDengine ...·  1 月前    · 
迷茫的马克杯  ·  从VBA中的范围中删除特殊字符开发者社区·  1 月前    · 
沉着的红烧肉  ·  分布式多机集群环境下定时任务只执行一次_qu ...·  9 月前    · 
爱搭讪的麻辣香锅  ·  python excel 设置密码-掘金·  2 年前    · 
含蓄的保温杯  ·  python post请求携带json ...·  2 年前    · 
近视的香菜  ·  jquery - Remove ...·  3 年前    · 
Code  ›  Azure Active Directory Permissions Issue: 403 Exception - Microsoft Community Hub
string
https://techcommunity.microsoft.com/t5/microsoft-entra-azure-ad/azure-active-directory-permissions-issue-403-exception/td-p/153291
愤怒的消炎药
2 年前

Home

Community Hubs

Community Hubs
  • Community Hubs Home
  • Products
  • Special Topics
  • Video Hub

Most Active Hubs

Microsoft Excel
Microsoft Teams
Windows
Security, Compliance and Identity
Microsoft 365
Outlook
SharePoint
Azure
Exchange
Windows Server
Intune and Configuration Manager
Microsoft Viva
.NET
Sharing best practices for building any app with .NET.
Microsoft FastTrack
Best practices and the latest news on Microsoft FastTrack
Microsoft Viva
The employee experience platform to help people thrive at work

Most Active Hubs

Education Sector
ITOps Talk
Microsoft Partner Community
AI and Machine Learning
Core Infrastructure and Security
Microsoft Mechanics
Healthcare and Life Sciences
Internet of Things (IoT)
Public Sector
Regional Blogs
Mixed Reality
Azure Partner Community
Expand your Azure partner-to-partner network
Microsoft Tech Talks
Bringing IT Pros together through In-Person & Virtual events
MVP Award Program
Find out more about the Microsoft MVP Award Program.

Video Hub

Azure
Exchange
Microsoft 365
Microsoft 365 Business
Microsoft 365 Enterprise
Microsoft Edge
Microsoft Outlook
Microsoft Teams
Security
SharePoint
Windows
Browse All Community Hubs

Blogs

Blogs

Events

Events
  • Events Home
  • Microsoft Ignite
  • Microsoft Build
  • Community Events
Microsoft Learn
Microsoft Learn
  • Home
  • Community
  • Blog
  • Azure
  • Dynamics 365
  • Microsoft 365
  • Security, Compliance & Identity
  • Power Platform
  • Github
  • Teams
  • .NET

Lounge

Lounge
  • 1.2M Members
  • 7,871 Online
  • 304K Discussions
Search

I have a added a Native app in Azure Active directory. I have granted all the required SharePoint permissions (to my knowledge) but when I try to hit following SharePoint REST API, it returns 403 exception

https://mytenant.sharepoint.com/_api/SP.OAuth.NativeClient/Authenticate

I'm trying to get SharePoint Online SPOIDCRL cookie using bearer token. Below is my code snippet:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.microsoft.aad.adal.AuthenticationCallback;
import com.microsoft.aad.adal.AuthenticationContext;
import com.microsoft.aad.adal.AuthenticationResult;
import com.microsoft.aad.adal.PromptBehavior;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.Headers;
import java.net.URL;
import java.net.HttpURLConnection;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
    private static final String CLIENT_ID = "{my_client_id}";
    private static final String REDIRECT_URI = "{my_redirect_uri}";
    private static final String GRAPH_RESOURCE = "https://graph.microsoft.com";
    private static final String SHAREPOINT_ONLINE_RESOURCE = "mytenant.sharepoint.com";
    private static final String AUTHORITY = "https://login.microsoftonline.com/mytenant.onmicrosoft.com";
    private static final String LOG_TAG = "AUTH";
    private static String accessToken;
    private static String userId;
    private AuthenticationContext authenticationContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            // Create the authentication context.
            authenticationContext = new AuthenticationContext(MainActivity.this,
                    AUTHORITY, true);
            // Acquire tokens using necessary UI.
            authenticationContext.acquireToken(MainActivity.this, GRAPH_RESOURCE, CLIENT_ID, REDIRECT_URI,
                    PromptBehavior.Always, new AuthenticationCallback<AuthenticationResult>() {
                        @Override
                        public void onSuccess(AuthenticationResult result) {
                            String idToken = result.getIdToken();
                            accessToken = result.getAccessToken();
                            userId = result.getUserInfo().getUserId();
                            // Print tokens.
                            Log.d(LOG_TAG, "ID Token: " + idToken);
                            Log.d(LOG_TAG, "Access Token: " + accessToken);
                            String spToken = getEndPointToken(SHAREPOINT_ONLINE_RESOURCE);
                        @Override
                        public void onError(Exception exc) {
                            // TODO: Handle error
        } catch (Exception e) {
            e.printStackTrace();
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // Pass the activity result to the authentication context.
        if (authenticationContext != null) {
            authenticationContext.onActivityResult(requestCode, resultCode, data);
    protected void getCookies(String token) {
        try {
            HttpURLConnection connection = (HttpURLConnection) new URL("https", "mytenant.sharepoint.com", "_api/SP.OAuth.NativeClient/Authenticate").openConnection();
            try {
                connection.setRequestProperty(Broker.CHALLENGE_RESPONSE_HEADER, String.format(Locale.ROOT, "Bearer %s", new Object[]{token}));
                connection.setRequestMethod("POST");
                String headerField = connection.getHeaderField("Set-Cookie");
                Log.d("COOKIE", headerField);
                connection.disconnect();
            } finally {
                connection.disconnect();
        } catch (Exception e) {
    protected String getEndPointToken (String resourceUri) {
        String token = "";
        try {
            authenticationContext.acquireTokenSilentAsync(resourceUri, CLIENT_ID, userId, new AuthenticationCallback<AuthenticationResult>() {
                @Override
                public void onSuccess(AuthenticationResult result) {
                    String spAccessToken = result.getAccessToken();
                    Log.d("SP-AUTH", "Sharepoint Token");
                    Log.d("SP-AUTH", spAccessToken);
                    getCookies(spAccessToken);
                @Override
                public void onError(Exception exc) {
                    // TODO: Handle error
        } catch (Exception e) {
        return token;

Exception:
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>-1, Microsoft.SharePoint.Client.ClientServiceException</m:code><m:message xml:lang="en-US">Exception of type 'Microsoft.SharePoint.Client.ClientServiceException' was thrown.</m:message></m:error>

 
推荐文章
暴躁的石榴  ·  翻译 - Dolibarr ERP CRM Wiki
1 月前
不羁的饺子  ·  Debezium | Apache Flink
1 月前
讲道义的烈酒  ·  Debezium-JSON--流式计算 Flink版-火山引擎
1 月前
从容的大脸猫  ·  零代码第三方数据接入 | TDengine 文档 | 涛思数据
1 月前
迷茫的马克杯  ·  从VBA中的范围中删除特殊字符开发者社区
1 月前
沉着的红烧肉  ·  分布式多机集群环境下定时任务只执行一次_quartz怎么实现启动多个节点,定时任务只执行一遍-CSDN博客
9 月前
爱搭讪的麻辣香锅  ·  python excel 设置密码-掘金
2 年前
含蓄的保温杯  ·  python post请求携带json body - 简书
2 年前
近视的香菜  ·  jquery - Remove options select with a value greater than 0 - Stack Overflow
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号