Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Message: Resource not found for the segment 'calendars'. #404

Open
Impdevil opened this issue Feb 22, 2020 · 7 comments
Open

Error Message: Resource not found for the segment 'calendars'. #404

Impdevil opened this issue Feb 22, 2020 · 7 comments

Comments

@Impdevil
Copy link

Impdevil commented Feb 22, 2020

Hi I'm trying to connect using application permissions for a chatbot, and I'm either receiving this error above or

"The token contains no permissions, or permissions can not be understood."

when trying to get access to specifically a calendar, I'm not really understanding where im going wrong. I'm using a blueprint to create the system I need each time, though not sure if that's the best option, here's the relevant code:

` def init(self):

    self._date = datetime.datetime.now
    self._account = None
    print("Initializing calendar connection")
    with open(os.getenv("MSCLIENTINFO")) as json_file:
        creds_dict = json.load(json_file)
    creds = (creds_dict["MSCLIENT_ID"],creds_dict["MSSECRET"])
    
    token_backend = ograph.FileSystemTokenBackend(token_path="ChatBot-NSGC-v0_3", token_filename="o365_token.txt")

    account = ograph.Account(creds,timezone="Europe/London",token_backend=token_backend, auth_flow_type="credentials", tenant_id=creds_dict["tenant-id"])

    if account.authenticate():
        print("Calendar Connection Created " + str(account))
        self._account = account
    else:
        print("Calendar Connection Failed")



def Retrieve_account(self):
    if self._account.is_authenticated == True:
        print("account connected")
        return self._account
    
    print("connection lost")
    return False

##
def Check_date_time_conflict(self, bookingdict):
    '''
        return types true = conflicts
        false = no conflicts
    '''
    account = self.Retrieve_account()
    
    sched = account.schedule()
    for potato in sched.list_calendars():
        print(potato.name)
        if potato.name == 'CalenderTesterAPI':
            print('found!')

    if self.Retrieve_account() != False:
        #onced checked the the account is correct check against the 
        
        print("potat0")
        calender = sched.get_calendar(calendar_name="CalenderTesterAPI")
        print("potat1 " + calender)
        cal_query = calender.new_query("start").equal(bookingdict['returnedTime'])
        print("Cal query "+str(cal_query))
        bookings =  calender.get_events(query=cal_query, include_recurring=True)
        print("potat2 " + str(bookings))
        for booking in bookings:
            if booking != None:
                return True
            else: return False
    else: 
        print("Account failed to connect " + str(self.Retrieve_account()))
        return False

`

As you can probably see I've had a look at previous issues related to this topic but I cant seem to understand where this is going wrong. The code fails at the first instantiation of sched in Check_date_time_conflict. with sched = account.schedule(resource="[email protected]") it give me the second error, I'm very sure I have setup the app registration on msgraph part so I'm sure its some issue with my code. I have the Token saved as well.

Pardon my print("potat#") its a habit for debugging that I haven't properly lost since college.

@alejcas
Copy link
Member

alejcas commented Feb 24, 2020

When using credentials as auth flow you need to pass a resource as you are initially authenticated as the “app”.

So just:

sched = account.schedule(resource='[email protected]')

@Impdevil
Copy link
Author

I have that and it still seems to not work, i receive the second error
sched = account.schedule(resource="[email protected]") for potato in sched.list_calendars(): print(potato.name) if potato.name == 'CalenderTesterAPI': print('found!')

The token contains no permissions, or permissions can not be understood.

I'm sorry I'm not understanding where its drawing this from, I have the token and definitely have the app permissions set in azure

@alejcas
Copy link
Member

alejcas commented Feb 26, 2020

Then it could be a problem with the definition of the app.

Two questions:

1.- Did you add Application permissions or delegated permissions?
1.- Did you request and have the "Admin Consent" approved?

@Impdevil
Copy link
Author

Impdevil commented Feb 26, 2020

I used application permissions
and I am the admin

I have also looked into my token and i see no permissions being sent, referring to scp after i decoded the token.

@alejcas
Copy link
Member

alejcas commented Feb 26, 2020

I'm sorry I'm not understanding where its drawing this from

This message comes from the MS Graph Service.

The token file should contain only the ".default" scope. Correct?

@Impdevil
Copy link
Author

Impdevil commented Feb 26, 2020

I see no ".default" scope in the token

I'm using https://jwt.io/ to decrypt the token btw

@Impdevil
Copy link
Author

I have revoked the previous app permissions and then added them again with admin consent and saved a new client secret.

but still to no avail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants